Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-05-05 10:21:32 -0400
committerThomas Wolf2019-06-27 11:39:43 -0400
commit9e3a3c73ab7c62a85e3baf5fb41c2a401ca299f0 (patch)
treedbaa151a0c369233f180020f04dae5869cf54613 /org.eclipse.egit.core.test/src
parent49573a86da2997b44073bd8606479218d23b5371 (diff)
downloadegit-9e3a3c73ab7c62a85e3baf5fb41c2a401ca299f0.tar.gz
egit-9e3a3c73ab7c62a85e3baf5fb41c2a401ca299f0.tar.xz
egit-9e3a3c73ab7c62a85e3baf5fb41c2a401ca299f0.zip
Added option to create light weight tags
When the tag has no message in CreateTagDialog create a lightweight tag instead of an annotated tag. Adds tests for both the UI and for the new "annotated" flag in TagOperation. (Since the lower-level TagOperation allows creating an annotated tag without message, an extra flag is needed.) Bug 438902 Change-Id: I99b53c08f94744f78aabe1c1e57b91d0da587bc7 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
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 ae1ecbd12..9c9dee29d 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