Browse Source

Add --match option for `jgit describe` to CLI

This adds --match option for glob(7) matchers on git tags to jgit
describe in CLI.

Bug: 518377
Change-Id: I745988d565dd4391e8b3e5a91bbfbae575333819
Signed-off-by: Oliver Lockwood <oliver.lockwood@cantab.net>
stable-4.9
Oliver Lockwood 8 years ago committed by Matthias Sohn
parent
commit
43672700e7
  1. 52
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java
  2. 2
      org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
  3. 7
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java
  4. 1
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java

52
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/DescribeTest.java

@ -46,6 +46,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays; import java.util.Arrays;
@ -71,6 +72,12 @@ public class DescribeTest extends CLIRepositoryTestCase {
git.tag().setName("v1.0").call(); git.tag().setName("v1.0").call();
} }
private void secondCommit() throws Exception {
writeTrashFile("greeting", "Hello, world!");
git.add().addFilepattern("greeting").call();
git.commit().setMessage("2nd commit").call();
}
@Test @Test
public void testNoHead() throws Exception { public void testNoHead() throws Exception {
assertEquals(CLIText.fatalError(CLIText.get().noNamesFound), assertEquals(CLIText.fatalError(CLIText.get().noNamesFound),
@ -94,9 +101,7 @@ public class DescribeTest extends CLIRepositoryTestCase {
@Test @Test
public void testDescribeCommit() throws Exception { public void testDescribeCommit() throws Exception {
initialCommitAndTag(); initialCommitAndTag();
writeTrashFile("greeting", "Hello, world!"); secondCommit();
git.add().addFilepattern("greeting").call();
git.commit().setMessage("2nd commit").call();
assertArrayEquals(new String[] { "v1.0-1-g56f6ceb", "" }, assertArrayEquals(new String[] { "v1.0-1-g56f6ceb", "" },
execute("git describe")); execute("git describe"));
} }
@ -108,6 +113,47 @@ public class DescribeTest extends CLIRepositoryTestCase {
execute("git describe --long HEAD")); execute("git describe --long HEAD"));
} }
@Test
public void testDescribeCommitMatch() throws Exception {
initialCommitAndTag();
secondCommit();
assertArrayEquals(new String[] { "v1.0-1-g56f6ceb", "" },
execute("git describe --match v1.*"));
}
@Test
public void testDescribeCommitMatch2() throws Exception {
initialCommitAndTag();
secondCommit();
git.tag().setName("v2.0").call();
assertArrayEquals(new String[] { "v1.0-1-g56f6ceb", "" },
execute("git describe --match v1.*"));
}
@Test
public void testDescribeCommitMultiMatch() throws Exception {
initialCommitAndTag();
secondCommit();
git.tag().setName("v2.0.0").call();
git.tag().setName("v2.1.1").call();
assertArrayEquals("git yields v2.0.0", new String[] { "v2.0.0", "" },
execute("git describe --match v2.0* --match v2.1.*"));
}
@Test
public void testDescribeCommitNoMatch() throws Exception {
initialCommitAndTag();
writeTrashFile("greeting", "Hello, world!");
secondCommit();
try {
execute("git describe --match 1.*");
fail("git describe should not find any tag matching 1.*");
} catch (Die e) {
assertEquals("No names found, cannot describe anything.",
e.getMessage());
}
}
@Test @Test
public void testHelpArgumentBeforeUnknown() throws Exception { public void testHelpArgumentBeforeUnknown() throws Exception {
String[] output = execute("git describe -h -XYZ"); String[] output = execute("git describe -h -XYZ");

2
org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties

@ -129,6 +129,7 @@ metaVar_op=OP
metaVar_pass=PASS metaVar_pass=PASS
metaVar_path=path metaVar_path=path
metaVar_paths=path ... metaVar_paths=path ...
metaVar_pattern=pattern
metaVar_port=PORT metaVar_port=PORT
metaVar_ref=REF metaVar_ref=REF
metaVar_refs=REFS metaVar_refs=REFS
@ -248,6 +249,7 @@ usage_lsRemoteHeads=Show only refs starting with refs/heads
usage_lsRemoteTags=Show only refs starting with refs/tags usage_lsRemoteTags=Show only refs starting with refs/tags
usage_LsTree=List the contents of a tree object usage_LsTree=List the contents of a tree object
usage_MakeCacheTree=Show the current cache tree structure usage_MakeCacheTree=Show the current cache tree structure
usage_Match=Only consider tags matching the given glob(7) pattern or patterns, excluding the "refs/tags/" prefix.
usage_MergeBase=Find as good common ancestors as possible for a merge usage_MergeBase=Find as good common ancestors as possible for a merge
usage_MergesTwoDevelopmentHistories=Merges two development histories usage_MergesTwoDevelopmentHistories=Merges two development histories
usage_PreserveOldPacks=Preserve old pack files by moving them into the preserved subdirectory instead of deleting them after repacking usage_PreserveOldPacks=Preserve old pack files by moving them into the preserved subdirectory instead of deleting them after repacking

7
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java

@ -50,6 +50,9 @@ import org.eclipse.jgit.pgm.internal.CLIText;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
import java.util.ArrayList;
import java.util.List;
@Command(common = true, usage = "usage_Describe") @Command(common = true, usage = "usage_Describe")
class Describe extends TextBuiltin { class Describe extends TextBuiltin {
@ -59,6 +62,9 @@ class Describe extends TextBuiltin {
@Option(name = "--long", usage = "usage_LongFormat") @Option(name = "--long", usage = "usage_LongFormat")
private boolean longDesc; private boolean longDesc;
@Option(name = "--match", multiValued = true, usage = "usage_Match", metaVar = "metaVar_pattern")
private List<String> patterns = new ArrayList<>();
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
@ -66,6 +72,7 @@ class Describe extends TextBuiltin {
if (tree != null) if (tree != null)
cmd.setTarget(tree); cmd.setTarget(tree);
cmd.setLong(longDesc); cmd.setLong(longDesc);
cmd.setMatch(patterns.toArray(new String[patterns.size()]));
String result = null; String result = null;
try { try {
result = cmd.call(); result = cmd.call();

1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java

@ -196,6 +196,7 @@ public class CLIText extends TranslationBundle {
/***/ public String metaVar_pass; /***/ public String metaVar_pass;
/***/ public String metaVar_path; /***/ public String metaVar_path;
/***/ public String metaVar_paths; /***/ public String metaVar_paths;
/***/ public String metaVar_pattern;
/***/ public String metaVar_port; /***/ public String metaVar_port;
/***/ public String metaVar_ref; /***/ public String metaVar_ref;
/***/ public String metaVar_refs; /***/ public String metaVar_refs;

Loading…
Cancel
Save