CLI: implement option -d for deleting tags
Change-Id: I438456b76aefd361384729686271288186d3be3b Signed-off-by: Ned Twigg <ned.twigg@diffplug.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
34673f0536
commit
b67df51203
|
@ -46,6 +46,7 @@
|
||||||
|
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
||||||
|
import org.eclipse.jgit.lib.Ref;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -70,4 +71,26 @@ public void testTagTwice() throws Exception {
|
||||||
assertEquals("fatal: tag 'test' already exists",
|
assertEquals("fatal: tag 'test' already exists",
|
||||||
executeUnchecked("git tag test")[0]);
|
executeUnchecked("git tag test")[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTagDelete() throws Exception {
|
||||||
|
git.tag().setName("test").call();
|
||||||
|
|
||||||
|
Ref ref = git.getRepository().getTags().get("test");
|
||||||
|
assertEquals("refs/tags/test", ref.getName());
|
||||||
|
|
||||||
|
assertEquals("", executeUnchecked("git tag -d test")[0]);
|
||||||
|
Ref deletedRef = git.getRepository().getTags().get("test");
|
||||||
|
assertEquals(null, deletedRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTagDeleteFail() throws Exception {
|
||||||
|
try {
|
||||||
|
assertEquals("fatal: error: tag 'test' not found.",
|
||||||
|
executeUnchecked("git tag -d test")[0]);
|
||||||
|
} catch (Die e) {
|
||||||
|
assertEquals("fatal: error: tag 'test' not found", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,7 @@ switchedToNewBranch=Switched to a new branch ''{0}''
|
||||||
switchedToBranch=Switched to branch ''{0}''
|
switchedToBranch=Switched to branch ''{0}''
|
||||||
tagAlreadyExists=tag ''{0}'' already exists
|
tagAlreadyExists=tag ''{0}'' already exists
|
||||||
tagLabel=tag
|
tagLabel=tag
|
||||||
|
tagNotFound=error: tag ''{0}'' not found.
|
||||||
taggerInfo=Tagger: {0} <{1}>
|
taggerInfo=Tagger: {0} <{1}>
|
||||||
timeInMilliSeconds={0} ms
|
timeInMilliSeconds={0} ms
|
||||||
treeIsRequired=argument tree is required
|
treeIsRequired=argument tree is required
|
||||||
|
@ -386,6 +387,7 @@ usage_srcPrefix=show the source prefix instead of "a/"
|
||||||
usage_symbolicVersionForTheProject=Symbolic version for the project
|
usage_symbolicVersionForTheProject=Symbolic version for the project
|
||||||
usage_tags=fetch all tags
|
usage_tags=fetch all tags
|
||||||
usage_notags=do not fetch tags
|
usage_notags=do not fetch tags
|
||||||
|
usage_tagDelete=delete tag
|
||||||
usage_tagMessage=tag message
|
usage_tagMessage=tag message
|
||||||
usage_untrackedFilesMode=show untracked files
|
usage_untrackedFilesMode=show untracked files
|
||||||
usage_updateRef=reference to update
|
usage_updateRef=reference to update
|
||||||
|
|
|
@ -68,6 +68,9 @@ class Tag extends TextBuiltin {
|
||||||
@Option(name = "-f", usage = "usage_forceReplacingAnExistingTag")
|
@Option(name = "-f", usage = "usage_forceReplacingAnExistingTag")
|
||||||
private boolean force;
|
private boolean force;
|
||||||
|
|
||||||
|
@Option(name = "-d", usage = "usage_tagDelete")
|
||||||
|
private boolean delete;
|
||||||
|
|
||||||
@Option(name = "-m", metaVar = "metaVar_message", usage = "usage_tagMessage")
|
@Option(name = "-m", metaVar = "metaVar_message", usage = "usage_tagMessage")
|
||||||
private String message = ""; //$NON-NLS-1$
|
private String message = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -81,6 +84,14 @@ class Tag extends TextBuiltin {
|
||||||
protected void run() throws Exception {
|
protected void run() throws Exception {
|
||||||
try (Git git = new Git(db)) {
|
try (Git git = new Git(db)) {
|
||||||
if (tagName != null) {
|
if (tagName != null) {
|
||||||
|
if (delete) {
|
||||||
|
List<String> deletedTags = git.tagDelete().setTags(tagName)
|
||||||
|
.call();
|
||||||
|
if (deletedTags.isEmpty()) {
|
||||||
|
throw die(MessageFormat
|
||||||
|
.format(CLIText.get().tagNotFound, tagName));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
TagCommand command = git.tag().setForceUpdate(force)
|
TagCommand command = git.tag().setForceUpdate(force)
|
||||||
.setMessage(message).setName(tagName);
|
.setMessage(message).setName(tagName);
|
||||||
|
|
||||||
|
@ -92,8 +103,9 @@ protected void run() throws Exception {
|
||||||
try {
|
try {
|
||||||
command.call();
|
command.call();
|
||||||
} catch (RefAlreadyExistsException e) {
|
} catch (RefAlreadyExistsException e) {
|
||||||
throw die(MessageFormat.format(CLIText.get().tagAlreadyExists,
|
throw die(MessageFormat.format(
|
||||||
tagName));
|
CLIText.get().tagAlreadyExists, tagName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ListTagCommand command = git.tagList();
|
ListTagCommand command = git.tagList();
|
||||||
|
|
|
@ -269,6 +269,7 @@ public static String fatalError(String message) {
|
||||||
/***/ public String switchedToBranch;
|
/***/ public String switchedToBranch;
|
||||||
/***/ public String tagAlreadyExists;
|
/***/ public String tagAlreadyExists;
|
||||||
/***/ public String tagLabel;
|
/***/ public String tagLabel;
|
||||||
|
/***/ public String tagNotFound;
|
||||||
/***/ public String taggerInfo;
|
/***/ public String taggerInfo;
|
||||||
/***/ public String timeInMilliSeconds;
|
/***/ public String timeInMilliSeconds;
|
||||||
/***/ public String tooManyRefsGiven;
|
/***/ public String tooManyRefsGiven;
|
||||||
|
|
Loading…
Reference in New Issue