Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.egit.core.test/src')
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java101
1 files changed, 87 insertions, 14 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java
index ae1ecbd127..9c9dee29d9 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java
@@ -10,20 +10,22 @@
*******************************************************************************/
package org.eclipse.egit.core.test.op;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.op.TagOperation;
import org.eclipse.egit.core.test.DualRepositoryTestCase;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.core.test.TestUtils;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.TagBuilder;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -80,20 +82,14 @@ public class TagOperationTest extends DualRepositoryTestCase {
assertFalse("Tags should not be empty", repository1.getRepository()
.getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
- try {
- top.execute(null);
- fail("Expected Exception not thrown");
- } catch (CoreException e) {
- // expected
- }
+ top.execute(null);
+ assertEquals(top.getResult(), RefUpdate.Result.NO_CHANGE);
top = new TagOperation(repository1.getRepository(), newTag, true);
- try {
- top.execute(null);
- fail("Expected Exception not thrown");
- } catch (CoreException e) {
- // expected
- }
+
+ top.execute(null);
+ assertEquals(top.getResult(), RefUpdate.Result.NO_CHANGE);
+
try (RevWalk walk = new RevWalk(repository1.getRepository())) {
RevTag tag = walk.parseTag(repository1.getRepository().resolve(
Constants.R_TAGS + "TheNewTag"));
@@ -110,4 +106,81 @@ public class TagOperationTest extends DualRepositoryTestCase {
}
}
+ @Test
+ public void addEmptyAnnotatedTag() throws Exception {
+ assertTrue("Tags should be empty", repository1.getRepository()
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
+ TagBuilder newTag = new TagBuilder();
+ newTag.setTag("TheNewTag");
+ newTag.setMessage("");
+ newTag.setTagger(RawParseUtils.parsePersonIdent(TestUtils.AUTHOR));
+ ObjectId headCommit = repository1.getRepository()
+ .resolve("refs/heads/master");
+ newTag.setObjectId(headCommit, Constants.OBJ_COMMIT);
+ TagOperation top = new TagOperation(repository1.getRepository(), newTag,
+ false, true);
+ top.execute(new NullProgressMonitor());
+ assertFalse("Tags should not be empty", repository1.getRepository()
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
+ assertIsAnnotated("TheNewTag", headCommit, "");
+ }
+
+ @Test
+ public void addNullAnnotatedTag() throws Exception {
+ assertTrue("Tags should be empty", repository1.getRepository()
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
+ TagBuilder newTag = new TagBuilder();
+ newTag.setTag("TheNewTag");
+ newTag.setTagger(RawParseUtils.parsePersonIdent(TestUtils.AUTHOR));
+ ObjectId headCommit = repository1.getRepository()
+ .resolve("refs/heads/master");
+ newTag.setObjectId(headCommit, Constants.OBJ_COMMIT);
+ TagOperation top = new TagOperation(repository1.getRepository(), newTag,
+ false, true);
+ top.execute(new NullProgressMonitor());
+ assertFalse("Tags should not be empty", repository1.getRepository()
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
+ assertIsAnnotated("TheNewTag", headCommit, null);
+ }
+
+ @Test
+ public void addLightweightTag() throws Exception {
+ assertTrue("Tags should be empty", repository1.getRepository()
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
+ TagBuilder newTag = new TagBuilder();
+ newTag.setTag("TheNewTag");
+ newTag.setTagger(RawParseUtils.parsePersonIdent(TestUtils.AUTHOR));
+ ObjectId headCommit = repository1.getRepository()
+ .resolve("refs/heads/master");
+ newTag.setObjectId(headCommit, Constants.OBJ_COMMIT);
+ TagOperation top = new TagOperation(repository1.getRepository(), newTag,
+ false, false);
+ top.execute(new NullProgressMonitor());
+ assertFalse("Tags should not be empty", repository1.getRepository()
+ .getRefDatabase().getRefsByPrefix(Constants.R_TAGS).isEmpty());
+ assertIsLightweight("TheNewTag", headCommit);
+ }
+
+ private void assertIsAnnotated(String tag, ObjectId target, String message)
+ throws Exception {
+ Ref ref = repository1.getRepository().exactRef(Constants.R_TAGS + tag);
+ ObjectId obj = ref.getObjectId();
+ try (RevWalk walk = new RevWalk(repository1.getRepository())) {
+ RevTag t = walk.parseTag(obj);
+ if (message != null) {
+ assertEquals("Unexpected tag message", message,
+ t.getFullMessage());
+ }
+ assertEquals("Unexpected commit for tag " + t.getName(), target,
+ walk.peel(t));
+ }
+ }
+
+ private void assertIsLightweight(String tag, ObjectId target)
+ throws Exception {
+ Ref ref = repository1.getRepository().exactRef(Constants.R_TAGS + tag);
+ ObjectId obj = ref.getObjectId();
+ assertEquals("Unexpected commit for tag " + ref.getName(), target, obj);
+ }
+
}

Back to the top