[pgm] Implement git tag --contains option
Change-Id: I390bcd2c2c563d4b27e1369f09548be59ba7c111
This commit is contained in:
parent
060dcf1cca
commit
0e9708803f
|
@ -9,24 +9,30 @@
|
||||||
*/
|
*/
|
||||||
package org.eclipse.jgit.pgm;
|
package org.eclipse.jgit.pgm;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
|
import org.eclipse.jgit.junit.TestRepository;
|
||||||
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
|
||||||
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TagTest extends CLIRepositoryTestCase {
|
public class TagTest extends CLIRepositoryTestCase {
|
||||||
private Git git;
|
private Git git;
|
||||||
|
|
||||||
|
private RevCommit initialCommit;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
git = new Git(db);
|
git = new Git(db);
|
||||||
git.commit().setMessage("initial commit").call();
|
initialCommit = git.commit().setMessage("initial commit").call();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -57,4 +63,39 @@ public void testTagDeleteFail() throws Exception {
|
||||||
assertEquals("fatal: error: tag 'test' not found", e.getMessage());
|
assertEquals("fatal: error: tag 'test' not found", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContains() throws Exception {
|
||||||
|
/* c3
|
||||||
|
* |
|
||||||
|
* v2 - c2 b2 - v1
|
||||||
|
* | |
|
||||||
|
* c1 b1
|
||||||
|
* \ /
|
||||||
|
* a
|
||||||
|
*/
|
||||||
|
try (TestRepository<Repository> r = new TestRepository<>(
|
||||||
|
db)) {
|
||||||
|
RevCommit b1 = r.commit(initialCommit);
|
||||||
|
RevCommit b2 = r.commit(b1);
|
||||||
|
RevCommit c1 = r.commit(initialCommit);
|
||||||
|
RevCommit c2 = r.commit(c1);
|
||||||
|
RevCommit c3 = r.commit(c2);
|
||||||
|
r.update("refs/tags/v1", r.tag("v1", b2));
|
||||||
|
r.update("refs/tags/v2", r.tag("v1.1", c2));
|
||||||
|
|
||||||
|
assertArrayEquals(
|
||||||
|
new String[] { "v1", "v2", "" },
|
||||||
|
execute("git tag --contains " + initialCommit.name()));
|
||||||
|
|
||||||
|
assertArrayEquals(new String[] { "v1", "" },
|
||||||
|
execute("git tag --contains " + b1.name()));
|
||||||
|
|
||||||
|
assertArrayEquals(new String[] { "v2", "" },
|
||||||
|
execute("git tag --contains " + c1.name()));
|
||||||
|
|
||||||
|
assertArrayEquals(new String[] { "" },
|
||||||
|
execute("git tag --contains " + c3.name()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,6 +469,7 @@ usage_trustExitCode=git-difftool invokes a diff tool individually on each file.
|
||||||
usage_noTrustExitCode=This option can be used to override --trust-exit-code setting.
|
usage_noTrustExitCode=This option can be used to override --trust-exit-code setting.
|
||||||
usage_notags=do not fetch tags
|
usage_notags=do not fetch tags
|
||||||
usage_tagAnnotated=create an annotated tag, unsigned unless -s or -u are given, or config tag.gpgSign is true
|
usage_tagAnnotated=create an annotated tag, unsigned unless -s or -u are given, or config tag.gpgSign is true
|
||||||
|
usage_tagContains=Only list tags which contain the specified commit
|
||||||
usage_tagDelete=delete tag
|
usage_tagDelete=delete tag
|
||||||
usage_tagLocalUser=create a signed annotated tag using the specified GPG key ID
|
usage_tagLocalUser=create a signed annotated tag using the specified GPG key ID
|
||||||
usage_tagMessage=create an annotated tag with the given message, unsigned unless -s or -u are given, or config tag.gpgSign is true, or tar.forceSignAnnotated is true and -a is not given
|
usage_tagMessage=create an annotated tag with the given message, unsigned unless -s or -u are given, or config tag.gpgSign is true, or tar.forceSignAnnotated is true and -a is not given
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.pgm.internal.CLIText;
|
import org.eclipse.jgit.pgm.internal.CLIText;
|
||||||
import org.eclipse.jgit.pgm.internal.VerificationUtils;
|
import org.eclipse.jgit.pgm.internal.VerificationUtils;
|
||||||
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.revwalk.RevTag;
|
import org.eclipse.jgit.revwalk.RevTag;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
import org.kohsuke.args4j.Argument;
|
import org.kohsuke.args4j.Argument;
|
||||||
|
@ -76,6 +77,11 @@ class Tag extends TextBuiltin {
|
||||||
"--local-user" }, usage = "usage_tagVerify")
|
"--local-user" }, usage = "usage_tagVerify")
|
||||||
private boolean verify;
|
private boolean verify;
|
||||||
|
|
||||||
|
@Option(name = "--contains", forbids = { "--delete", "--force",
|
||||||
|
"--annotate", "-m", "--sign", "--no-sign",
|
||||||
|
"--local-user" }, metaVar = "metaVar_commitish", usage = "usage_tagContains")
|
||||||
|
private RevCommit contains;
|
||||||
|
|
||||||
@Argument(index = 0, metaVar = "metaVar_name")
|
@Argument(index = 0, metaVar = "metaVar_name")
|
||||||
private String tagName;
|
private String tagName;
|
||||||
|
|
||||||
|
@ -142,6 +148,9 @@ protected void run() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ListTagCommand command = git.tagList();
|
ListTagCommand command = git.tagList();
|
||||||
|
if (contains != null) {
|
||||||
|
command.setContains(contains);
|
||||||
|
}
|
||||||
List<Ref> list = command.call();
|
List<Ref> list = command.call();
|
||||||
for (Ref ref : list) {
|
for (Ref ref : list) {
|
||||||
outw.println(Repository.shortenRefName(ref.getName()));
|
outw.println(Repository.shortenRefName(ref.getName()));
|
||||||
|
|
Loading…
Reference in New Issue