Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java101
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/TagOperation.java48
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/TagActionTest.java195
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java4
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CreateTagDialog.java163
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties2
7 files changed, 403 insertions, 116 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);
+ }
+
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TagOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TagOperation.java
index 2d22c2296..8c0ca09ad 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TagOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/TagOperation.java
@@ -17,6 +17,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.egit.core.internal.CoreText;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
@@ -34,33 +35,65 @@ public class TagOperation implements IEGitOperation {
private final TagBuilder tag;
private final Repository repo;
+
+ private Result result;
+
private final boolean shouldMoveTag;
+ private final boolean annotated;
+
/**
* Construct TagOperation
*
* @param repo
* @param tag
- * @param shouldMoveTag if <code>true</code> it will replace tag with same name
+ * @param shouldMoveTag
+ * if <code>true</code> it will replace tag with same name
+ * @param annotated
+ * <code>true</code> if tag is annotated
*/
- public TagOperation(Repository repo, TagBuilder tag, boolean shouldMoveTag) {
+ public TagOperation(Repository repo, TagBuilder tag, boolean shouldMoveTag,
+ boolean annotated) {
this.tag = tag;
this.repo = repo;
this.shouldMoveTag = shouldMoveTag;
+ this.annotated = annotated;
}
+ /**
+ * Construct TagOperation
+ *
+ * @param repo
+ * @param tag
+ * @param shouldMoveTag
+ * if <code>true</code> it will replace tag with same name
+ */
+ public TagOperation(Repository repo, TagBuilder tag,
+ boolean shouldMoveTag) {
+ this(repo, tag, shouldMoveTag, true);
+ }
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 2);
progress.setTaskName(NLS.bind(CoreText.TagOperation_performingTagging,
tag.getTag()));
- ObjectId tagId = updateTagObject();
+ ObjectId tagId = annotated ? updateTagObject() : tag.getObjectId();
progress.worked(1);
updateRepo(tagId);
progress.worked(1);
}
+ /**
+ * Obtains the result of the operation.
+ *
+ * @return the result
+ */
+ public @NonNull Result getResult() {
+ Result r = result;
+ return r == null ? Result.NOT_ATTEMPTED : r;
+ }
+
private void updateRepo(ObjectId tagId) throws TeamException {
String refName = Constants.R_TAGS + tag.getTag();
@@ -71,9 +104,16 @@ public class TagOperation implements IEGitOperation {
tagRef.setForceUpdate(shouldMoveTag);
Result updateResult = tagRef.update();
- if (updateResult != Result.NEW && updateResult != Result.FORCED)
+ result = updateResult;
+ switch (updateResult) {
+ case NEW:
+ case FORCED:
+ case NO_CHANGE:
+ break; // OK
+ default:
throw new TeamException(NLS.bind(CoreText.TagOperation_taggingFailure,
tag.getTag(), updateResult));
+ }
} catch (IOException e) {
throw new TeamException(NLS.bind(CoreText.TagOperation_taggingFailure,
tag.getTag(), e.getMessage()), e);
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);
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index a40c35f8a..4f7e617fd 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -4389,6 +4389,9 @@ public class UIText extends NLS {
public static String CreateTagDialog_overwriteTagToolTip;
/** */
+ public static String CreateTagDialog_tagMessageToolTip;
+
+ /** */
public static String CreateTagDialog_existingTags;
/** */
@@ -4425,9 +4428,6 @@ public class UIText extends NLS {
public static String CreateTagDialog_GetTagJobName;
/** */
- public static String CreateTagDialog_LightweightTagMessage;
-
- /** */
public static String CreateTagDialog_LoadingMessageText;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java
index e218685ee..327fa36f1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/TagActionHandler.java
@@ -111,12 +111,14 @@ public class TagActionHandler extends RepositoryActionHandler {
String tagJobName = MessageFormat.format(UIText.TagAction_creating,
tagName);
final boolean shouldMoveTag = dialog.shouldOverWriteTag();
+ final boolean isAnnotated = dialog.isAnnotated();
Job tagJob = new Job(tagJobName) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- new TagOperation(repo, tag, shouldMoveTag).execute(monitor);
+ new TagOperation(repo, tag, shouldMoveTag, isAnnotated)
+ .execute(monitor);
} catch (CoreException e) {
return Activator.createErrorStatus(
UIText.TagAction_taggingFailed, e);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CreateTagDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CreateTagDialog.java
index 0279a90d6..277c62329 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CreateTagDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CreateTagDialog.java
@@ -119,8 +119,10 @@ public class CreateTagDialog extends TitleAreaDialog {
private boolean overwriteTag;
+ private boolean annotated;
+
/** Tag object in case an existing annotated tag was entered */
- private RevTag existingTag;
+ private TagWrapper existingTag;
private Repository repo;
@@ -144,6 +146,41 @@ public class CreateTagDialog extends TitleAreaDialog {
private final RevWalk rw;
+ private static class TagWrapper {
+ RevTag annotatedTag;
+
+ Ref lightweightTag;
+
+ TagWrapper(RevTag t) {
+ annotatedTag = t;
+ lightweightTag = null;
+ }
+
+ TagWrapper(Ref l) {
+ annotatedTag = null;
+ lightweightTag = l;
+ }
+
+ public String getName() {
+ if (annotatedTag != null)
+ return annotatedTag.getTagName();
+ return lightweightTag.getName().replaceFirst("^" + Constants.R_TAGS, //$NON-NLS-1$
+ ""); //$NON-NLS-1$
+ }
+
+ public ObjectId getId() {
+ if (annotatedTag != null)
+ return annotatedTag.getObject();
+ return lightweightTag.getObjectId();
+ }
+
+ public String getMessage() {
+ if (annotatedTag != null)
+ return annotatedTag.getFullMessage();
+ return null;
+ }
+ }
+
private static class TagLabelProvider extends LabelProvider {
private final Image IMG_TAG;
@@ -253,6 +290,15 @@ public class CreateTagDialog extends TitleAreaDialog {
}
/**
+ * Indicates if the tag is annotated
+ *
+ * @return <code>true</code> if annotated, <code>false</code> otherwise
+ */
+ public boolean isAnnotated() {
+ return annotated;
+ }
+
+ /**
* @return true if the user wants to start the push wizard after creating
* the tag, false otherwise
*/
@@ -281,8 +327,8 @@ public class CreateTagDialog extends TitleAreaDialog {
@Override
protected void createButtonsForButtonBar(Composite parent) {
parent.setLayout(GridLayoutFactory.swtDefaults().create());
- parent.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
- .create());
+ parent.setLayoutData(
+ GridDataFactory.fillDefaults().grab(true, false).create());
Button clearButton = createButton(parent, CLEAR_ID,
UIText.CreateTagDialog_clearButton, false);
@@ -290,18 +336,20 @@ public class CreateTagDialog extends TitleAreaDialog {
setButtonLayoutData(clearButton);
Composite margin = new Composite(parent, SWT.NONE);
- margin.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
- .create());
+ margin.setLayoutData(
+ GridDataFactory.fillDefaults().grab(true, false).create());
Button createTagAndStartPushButton = createButton(parent,
- CREATE_AND_START_PUSH_ID, UIText.CreateTagDialog_CreateTagAndStartPushButton, false);
- createTagAndStartPushButton
- .setToolTipText(UIText.CreateTagDialog_CreateTagAndStartPushToolTip);
+ CREATE_AND_START_PUSH_ID,
+ UIText.CreateTagDialog_CreateTagAndStartPushButton, false);
+ createTagAndStartPushButton.setToolTipText(
+ UIText.CreateTagDialog_CreateTagAndStartPushToolTip);
setButtonLayoutData(createTagAndStartPushButton);
super.createButtonsForButtonBar(parent);
getButton(OK).setText(UIText.CreateTagDialog_CreateTagButton);
+ getButton(OK).setToolTipText(UIText.CreateTagDialog_tagMessageToolTip);
validateInput();
}
@@ -334,7 +382,8 @@ public class CreateTagDialog extends TitleAreaDialog {
}
});
} catch (IOException e) {
- setErrorMessage(UIText.CreateTagDialog_ExceptionRetrievingTagsMessage);
+ setErrorMessage(
+ UIText.CreateTagDialog_ExceptionRetrievingTagsMessage);
return Activator.createErrorStatus(e.getMessage(), e);
}
return Status.OK_STATUS;
@@ -360,10 +409,10 @@ public class CreateTagDialog extends TitleAreaDialog {
Composite composite = (Composite) super.createDialogArea(parent);
- final SashForm mainForm = new SashForm(composite, SWT.HORIZONTAL
- | SWT.FILL);
- mainForm.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
- .create());
+ final SashForm mainForm = new SashForm(composite,
+ SWT.HORIZONTAL | SWT.FILL);
+ mainForm.setLayoutData(
+ GridDataFactory.fillDefaults().grab(true, true).create());
createLeftSection(mainForm);
createExistingTagsSection(mainForm);
@@ -398,6 +447,7 @@ public class CreateTagDialog extends TitleAreaDialog {
.replaceFirst(""); //$NON-NLS-1$
}
overwriteTag = overwriteButton.getSelection();
+ annotated = !tagMessageText.getCommitMessage().isEmpty();
okPressed();
} else {
super.buttonPressed(buttonId);
@@ -412,22 +462,23 @@ public class CreateTagDialog extends TitleAreaDialog {
private void createLeftSection(SashForm mainForm) {
Composite left = new Composite(mainForm, SWT.RESIZE);
left.setLayout(GridLayoutFactory.swtDefaults().margins(10, 5).create());
- left.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
- .create());
+ left.setLayoutData(
+ GridDataFactory.fillDefaults().grab(true, true).create());
Label label = new Label(left, SWT.WRAP);
label.setText(UIText.CreateTagDialog_tagName);
- GridData data = new GridData(GridData.GRAB_HORIZONTAL
- | GridData.HORIZONTAL_ALIGN_FILL
- | GridData.VERTICAL_ALIGN_CENTER);
- data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2);
+ GridData data = new GridData(
+ GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_CENTER);
+ data.widthHint = convertHorizontalDLUsToPixels(
+ IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH / 2);
label.setLayoutData(data);
label.setFont(left.getFont());
- tagNameText = new Text(left, SWT.SINGLE | SWT.BORDER | SWT.SEARCH
- | SWT.ICON_CANCEL);
- tagNameText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
- | GridData.HORIZONTAL_ALIGN_FILL));
+ tagNameText = new Text(left,
+ SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL);
+ tagNameText.setLayoutData(new GridData(
+ GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
tagNameText.addModifyListener(new ModifyListener() {
@Override
@@ -439,7 +490,7 @@ public class CreateTagDialog extends TitleAreaDialog {
// Only parse/set tag once (otherwise it would be set twice when
// selecting from the existing tags)
if (existingTag == null
- || !tagNameValue.equals(existingTag.getTagName()))
+ || !tagNameValue.equals(existingTag.getName()))
setExistingTagFromText(tagNameValue);
validateInput();
}
@@ -449,7 +500,6 @@ public class CreateTagDialog extends TitleAreaDialog {
new Label(left, SWT.WRAP).setText(UIText.CreateTagDialog_tagMessage);
-
tagMessageText = new SpellcheckableMessageArea(left, tagMessage);
Point size = tagMessageText.getTextWidget().getSize();
tagMessageText.setLayoutData(GridDataFactory.fillDefaults().hint(size)
@@ -499,18 +549,18 @@ public class CreateTagDialog extends TitleAreaDialog {
advanced.setText(UIText.CreateTagDialog_advanced);
advanced.setToolTipText(UIText.CreateTagDialog_advancedToolTip);
- advanced.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
- .create());
+ advanced.setLayoutData(
+ GridDataFactory.fillDefaults().grab(true, false).create());
Composite advancedComposite = new Composite(advanced, SWT.WRAP);
advancedComposite.setLayout(GridLayoutFactory.swtDefaults().create());
- advancedComposite.setLayoutData(GridDataFactory.fillDefaults()
- .grab(true, true).create());
+ advancedComposite.setLayoutData(
+ GridDataFactory.fillDefaults().grab(true, true).create());
Label advancedLabel = new Label(advancedComposite, SWT.WRAP);
advancedLabel.setText(UIText.CreateTagDialog_advancedMessage);
- advancedLabel.setLayoutData(GridDataFactory.fillDefaults()
- .grab(true, false).create());
+ advancedLabel.setLayoutData(
+ GridDataFactory.fillDefaults().grab(true, false).create());
commitCombo = new CommitCombo(advancedComposite, SWT.NORMAL);
commitCombo.setLayoutData(GridDataFactory.fillDefaults()
@@ -545,7 +595,7 @@ public class CreateTagDialog extends TitleAreaDialog {
// Set combo selection if a tag is selected
if (existingTag != null)
- commitCombo.setSelectedElement(existingTag.getObject());
+ commitCombo.setSelectedElement(existingTag.getId());
}
composite.layout(true);
composite.getShell().pack();
@@ -560,8 +610,8 @@ public class CreateTagDialog extends TitleAreaDialog {
new Label(right, SWT.WRAP).setText(UIText.CreateTagDialog_existingTags);
- Table table = new Table(right, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER
- | SWT.SINGLE);
+ Table table = new Table(right,
+ SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE);
table.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
.hint(80, 100).create());
@@ -609,8 +659,8 @@ public class CreateTagDialog extends TitleAreaDialog {
// let's set the table inactive initially and display a "Loading..."
// message and fill the list asynchronously during create() in order to
// improve UI responsiveness
- tagViewer
- .setInput(new String[] { UIText.CreateTagDialog_LoadingMessageText });
+ tagViewer.setInput(
+ new String[] { UIText.CreateTagDialog_LoadingMessageText });
tagViewer.getTable().setEnabled(false);
applyDialogFont(parent);
}
@@ -627,14 +677,19 @@ public class CreateTagDialog extends TitleAreaDialog {
String tagMessageVal = tagMessageText.getText().trim();
+ boolean isLightWeight = tagMessageVal.isEmpty();
Control button = getButton(IDialogConstants.OK_ID);
if (button != null) {
- boolean containsTagNameAndMessage = (tagNameMessage == null || tagMessageVal
- .length() == 0) && tagMessageVal.length() != 0;
- boolean shouldOverwriteTag = (overwriteButton.getSelection() && Repository
- .isValidRefName(Constants.R_TAGS + tagNameText.getText()));
-
- boolean enabled = containsTagNameAndMessage || shouldOverwriteTag;
+ boolean containsTagNameAndMessage = (tagNameMessage == null
+ || tagMessageVal.length() == 0)
+ && tagMessageVal.length() != 0;
+ boolean shouldOverwriteTag = (overwriteButton.getSelection()
+ && Repository.isValidRefName(
+ Constants.R_TAGS + tagNameText.getText()));
+
+ boolean enabled = containsTagNameAndMessage || shouldOverwriteTag
+ || (isLightWeight && tagNameMessage == null
+ && !tagNameText.getText().isEmpty());
button.setEnabled(enabled);
Button createTagAndStartPush = getButton(CREATE_AND_START_PUSH_ID);
@@ -643,10 +698,9 @@ public class CreateTagDialog extends TitleAreaDialog {
}
boolean existingTagSelected = existingTag != null;
- if (existingTagSelected && !overwriteButton.getSelection())
- tagMessageText.getTextWidget().setEditable(false);
- else
- tagMessageText.getTextWidget().setEditable(true);
+ boolean readOnly = (existingTagSelected
+ && !overwriteButton.getSelection());
+ tagMessageText.getTextWidget().setEditable(!readOnly);
overwriteButton.setEnabled(existingTagSelected);
if (!existingTagSelected)
@@ -683,21 +737,22 @@ public class CreateTagDialog extends TitleAreaDialog {
private void setExistingTag(Object tagObject) {
if (tagObject instanceof RevTag)
- existingTag = (RevTag) tagObject;
- else {
+ existingTag = new TagWrapper((RevTag) tagObject);
+ else if (tagObject instanceof Ref) {
+ existingTag = new TagWrapper((Ref) tagObject);
+ } else {
setNoExistingTag();
- setErrorMessage(UIText.CreateTagDialog_LightweightTagMessage);
return;
}
- if (!tagNameText.getText().equals(existingTag.getTagName()))
- tagNameText.setText(existingTag.getTagName());
+ if (!tagNameText.getText().equals(existingTag.getName()))
+ tagNameText.setText(existingTag.getName());
if (commitCombo != null)
- commitCombo.setSelectedElement(existingTag.getObject());
+ commitCombo.setSelectedElement(existingTag.getId());
// handle un-annotated tags
- String message = existingTag.getFullMessage();
- tagMessageText.setText(null != message ? message : ""); //$NON-NLS-1$
+ String message = existingTag.getMessage();
+ tagMessageText.setText(message != null ? message : ""); //$NON-NLS-1$
}
private void getRevCommits(Collection<RevCommit> commits) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index f2bd449b3..de6ddf138 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1508,6 +1508,7 @@ CreateTagDialog_tagMessage=Tag &message:
CreateTagDialog_questionNewTagTitle=Create New Tag on Branch ''{0}''
CreateTagDialog_overwriteTag=Force &replace existing tag
CreateTagDialog_overwriteTagToolTip=Select this option if you want to change message or commit associated with already existing tag.
+CreateTagDialog_tagMessageToolTip=If message is empty a lightweight tag is created, an annotated one otherwise
CreateTagDialog_existingTags=&Existing tags:
CreateTagDialog_advanced=&Advanced
CreateTagDialog_advancedToolTip=In the advanced section you may choose the commit to be tagged.
@@ -1520,7 +1521,6 @@ CreateTagDialog_CreateTagButton=Create &Tag
CreateTagDialog_CreateTagOnCommitTitle=Create a New Tag on Commit {0}
CreateTagDialog_ExceptionRetrievingTagsMessage=Exception while retrieving existing tags
CreateTagDialog_GetTagJobName=Get existing tags for the Create Tag Dialog
-CreateTagDialog_LightweightTagMessage=This is a lightweight tag which cannot be edited
CreateTagDialog_LoadingMessageText=Loading...
CreateTagDialog_Message=Create a new tag or replace an existing one
CreateTagDialog_NewTag=Create New Tag

Back to the top