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.ui.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.ui.test/src')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java195
1 files changed, 156 insertions, 39 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
index fce9cb21a..889bb83f2 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java
@@ -15,18 +15,22 @@ package org.eclipse.egit.ui.test.team.actions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import java.io.File;
import org.eclipse.egit.core.op.TagOperation;
+import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.TagBuilder;
+import org.eclipse.jgit.revwalk.RevTag;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
@@ -44,50 +48,98 @@ import org.junit.runner.RunWith;
public class TagActionTest extends LocalRepositoryTestCase {
private File repositoryFile;
+ private ObjectId someTagCommit;
+
+ private ObjectId someLightTagCommit;
+
+ private ObjectId headCommit;
+
@Before
public void setup() throws Exception {
repositoryFile = createProjectAndCommitToRepository();
Repository repo = lookupRepository(repositoryFile);
+ someTagCommit = repo.exactRef(Constants.HEAD).getObjectId();
TagBuilder tag = new TagBuilder();
tag.setTag("SomeTag");
tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
tag.setMessage("I'm just a little tag");
- tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
- TagOperation top = new TagOperation(repo, tag, false);
+ tag.setObjectId(someTagCommit, Constants.OBJ_COMMIT);
+ TagOperation top = new TagOperation(repo, tag, false, true);
top.execute(null);
+
touchAndSubmit(null);
+
+ someLightTagCommit = repo.exactRef(Constants.HEAD).getObjectId();
+ tag = new TagBuilder();
+ tag.setTag("SomeLightTag");
+ tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
+ tag.setObjectId(someLightTagCommit, Constants.OBJ_COMMIT);
+ top = new TagOperation(repo, tag, false, false);
+ top.execute(null);
+
+ touchAndSubmit(null);
+ headCommit = repo.exactRef(Constants.HEAD).getObjectId();
+ }
+
+ private void assertIsAnnotated(String tag, ObjectId target, String message)
+ throws Exception {
+ Repository repo = lookupRepository(repositoryFile);
+ Ref ref = repo.exactRef(Constants.R_TAGS + tag);
+ ObjectId obj = ref.getObjectId();
+ try (RevWalk walk = new RevWalk(repo)) {
+ 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 {
+ Repository repo = lookupRepository(repositoryFile);
+ Ref ref = repo.exactRef(Constants.R_TAGS + tag);
+ ObjectId obj = ref.getObjectId();
+ assertEquals("Unexpected commit for tag " + ref.getName(), target, obj);
}
@Test
public void testTagDialogShowExistingTags() throws Exception {
SWTBotShell tagDialog = openTagDialog();
- SWTBotTable table = tagDialog.bot().tableWithLabel(
- UIText.CreateTagDialog_existingTags);
- TestUtil.waitUntilTableHasRowWithText(tagDialog.bot(), table, "SomeTag", 10000);
+ SWTBotTable table = tagDialog.bot()
+ .tableWithLabel(UIText.CreateTagDialog_existingTags);
+ TestUtil.waitUntilTableHasRowWithText(tagDialog.bot(), table, "SomeTag",
+ 10000);
}
@Test
public void testCreateTag() throws Exception {
SWTBotShell tagDialog = openTagDialog();
- tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(
- "SomeTag");
- assertFalse("Ok should be disabled",
- tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton)
- .isEnabled());
- tagDialog.bot().button(UIText.CreateTagDialog_clearButton)
- .click();
- tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(
- "AnotherTag");
- assertFalse("Ok should be disabled",
- tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton)
- .isEnabled());
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName)
+ .setText("SomeTag");
+ assertFalse("Ok should be disabled", tagDialog.bot()
+ .button(UIText.CreateTagDialog_CreateTagButton).isEnabled());
+ tagDialog.bot().button(UIText.CreateTagDialog_clearButton).click();
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName)
+ .setText("AnotherTag");
tagDialog.bot().styledTextWithLabel(UIText.CreateTagDialog_tagMessage)
.setText("Here's the message text");
tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
- waitInUI();
- assertNotNull(lookupRepository(repositoryFile)
- .exactRef(Constants.R_TAGS + "AnotherTag"));
+ TestUtil.joinJobs(JobFamilies.TAG);
+ assertIsAnnotated("AnotherTag", headCommit, "Here's the message text");
+ }
+
+ @Test
+ public void testCreateLightWeightTag() throws Exception {
+ SWTBotShell tagDialog = openTagDialog();
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName)
+ .setText("AnotherLightTag");
+ tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
+ TestUtil.joinJobs(JobFamilies.TAG);
+ assertIsLightweight("AnotherLightTag", headCommit);
}
@Test
@@ -118,46 +170,111 @@ public class TagActionTest extends LocalRepositoryTestCase {
util.getPluginLocalizedValue("TagAction_label") };
ContextMenuHelper.clickContextMenu(projectExplorerTree, menuPath);
SWTBotShell dialog = bot.shell(UIText.CreateTagDialog_NewTag);
+ TestUtil.joinJobs(JobFamilies.FILL_TAG_LIST);
+ // The job fires an asyncExec.
+ dialog.widget.getDisplay().syncExec(() -> {
+ // Make sure that asyncExec gets run
+ });
+
return dialog;
}
@Test
public void testChangeTagMessage() throws Exception {
SWTBotShell tagDialog = openTagDialog();
- assertFalse("Ok should be disabled",
- tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton)
- .isEnabled());
- tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(
- "MessageChangeTag");
- assertFalse("Ok should be disabled",
- tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton)
- .isEnabled());
+ assertFalse("Ok should be disabled", tagDialog.bot()
+ .button(UIText.CreateTagDialog_CreateTagButton).isEnabled());
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName)
+ .setText("MessageChangeTag");
tagDialog.bot().styledTextWithLabel(UIText.CreateTagDialog_tagMessage)
.setText("Here's the first message");
tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
- waitInUI();
- assertNotNull(lookupRepository(repositoryFile)
- .exactRef(Constants.R_TAGS + "MessageChangeTag"));
+ TestUtil.joinJobs(JobFamilies.TAG);
+ assertIsAnnotated("MessageChangeTag", headCommit,
+ "Here's the first message");
tagDialog = openTagDialog();
tagDialog.bot().tableWithLabel(UIText.CreateTagDialog_existingTags)
.getTableItem("MessageChangeTag").select();
- assertFalse("Ok should be disabled",
- tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton)
- .isEnabled());
- String oldText = tagDialog.bot().styledTextWithLabel(
- UIText.CreateTagDialog_tagMessage).getText();
+ assertFalse("Ok should be disabled", tagDialog.bot()
+ .button(UIText.CreateTagDialog_CreateTagButton).isEnabled());
+ String oldText = tagDialog.bot()
+ .styledTextWithLabel(UIText.CreateTagDialog_tagMessage)
+ .getText();
assertEquals("Wrong message text", "Here's the first message", oldText);
tagDialog.bot().checkBox(UIText.CreateTagDialog_overwriteTag).click();
tagDialog.bot().styledTextWithLabel(UIText.CreateTagDialog_tagMessage)
.setText("New message");
tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
+ TestUtil.joinJobs(JobFamilies.TAG);
tagDialog = openTagDialog();
tagDialog.bot().tableWithLabel(UIText.CreateTagDialog_existingTags)
.getTableItem("MessageChangeTag").select();
- String newText = tagDialog.bot().styledTextWithLabel(
- UIText.CreateTagDialog_tagMessage).getText();
+ String newText = tagDialog.bot()
+ .styledTextWithLabel(UIText.CreateTagDialog_tagMessage)
+ .getText();
assertEquals("Wrong message text", "New message", newText);
tagDialog.close();
}
+ @Test
+ public void testForceOverwriteLightWeightTag() throws Exception {
+ assertIsLightweight("SomeLightTag", someLightTagCommit);
+ SWTBotShell tagDialog = openTagDialog();
+ tagDialog.bot().tableWithLabel(UIText.CreateTagDialog_existingTags)
+ .getTableItem("SomeLightTag").select();
+ assertFalse("Ok should be disabled", tagDialog.bot()
+ .button(UIText.CreateTagDialog_CreateTagButton).isEnabled());
+ tagDialog.bot().checkBox(UIText.CreateTagDialog_overwriteTag).click();
+ tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
+ TestUtil.joinJobs(JobFamilies.TAG);
+ assertIsLightweight("SomeLightTag", headCommit);
+ }
+
+ @Test
+ public void testConvertLightWeightIntoAnnotatedTag() throws Exception {
+ assertIsLightweight("SomeLightTag", someLightTagCommit);
+
+ SWTBotShell tagDialog = openTagDialog();
+ tagDialog.bot().tableWithLabel(UIText.CreateTagDialog_existingTags)
+ .getTableItem("SomeLightTag").select();
+ assertFalse("Ok should be disabled", tagDialog.bot()
+ .button(UIText.CreateTagDialog_CreateTagButton).isEnabled());
+ tagDialog.bot().styledTextWithLabel(UIText.CreateTagDialog_tagMessage)
+ .setText("New message");
+ tagDialog.bot().checkBox(UIText.CreateTagDialog_overwriteTag).click();
+ tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
+ TestUtil.joinJobs(JobFamilies.TAG);
+ assertIsAnnotated("SomeLightTag", headCommit, "New message");
+ }
+
+ @Test
+ public void testConvertAnnotatedTagIntoLightWeight() throws Exception {
+ assertIsAnnotated("SomeTag", someTagCommit, null);
+
+ SWTBotShell tagDialog = openTagDialog();
+ tagDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName)
+ .setText("SomeTag");
+ // Selecting the second item via the table doesn't work on GTK,
+ // focusing the table somehow selects the first element, which
+ // sets the tag name text field, which filters the table to
+ // show only that first element, after which the item.select()
+ // below silently fails and we still have the first tag selected,
+ // which is "SomeLightTag".
+ //
+ // SWTBotTableItem item = tagDialog.bot()
+ // .tableWithLabel(UIText.CreateTagDialog_existingTags)
+ // .getTableItem("SomeTag");
+ // assertEquals("Wrong item selected", "SomeTag", item.getText());
+ // item.select();
+ // assertEquals("Tag name incorrect", "SomeTag", tagDialog.bot()
+ // .textWithLabel(UIText.CreateTagDialog_tagName).getText());
+ assertFalse("Ok should be disabled", tagDialog.bot()
+ .button(UIText.CreateTagDialog_CreateTagButton).isEnabled());
+ tagDialog.bot().checkBox(UIText.CreateTagDialog_overwriteTag).click();
+ tagDialog.bot().styledTextWithLabel(UIText.CreateTagDialog_tagMessage)
+ .setText("");
+ tagDialog.bot().button(UIText.CreateTagDialog_CreateTagButton).click();
+ TestUtil.joinJobs(JobFamilies.TAG);
+ assertIsLightweight("SomeTag", headCommit);
+ }
}

Back to the top