Skip to content

Commit

Permalink
Support describe match option
Browse files Browse the repository at this point in the history
This fixes #183.
  • Loading branch information
ajoberstar committed Oct 22, 2017
1 parent 5e9a859 commit dcc4872
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/content/grgit-describe.ad
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ grgit.describe()

[source, groovy]
----
grgit.describe(commit: <commit>, longDescr: <boolean>)
grgit.describe(commit: <commit>, longDescr: <boolean>, match: [<string>])
----

[source, groovy]
----
grgit.describe {
commit = <commit>
longDescr = <boolean>
match = [<string>]
}
----

Expand All @@ -37,6 +38,7 @@ Describe only shows annotated tags. For more information about creating annotate

commit:: (`Object`, default `null`) Commit-ish object names to describe. Defaults to HEAD if omitted. For a more complete list of ways to spell commit names, see link:grgit-resolve.html[grgit-resolve] (specifically the `toCommit` method).
longDescr:: (`boolean`, default `false`) Always output the long format (the tag, the number of commits and the abbreviated commit name) even when it matches a tag. This is useful when you want to see parts of the commit object name in "describe" output, even when the commit in question happens to be a tagged version. Instead of just emitting the tag name, it will describe such a commit as v1.2-0-gdeadbee (0th commit since tag v1.2 that points at object deadbee…​.).
match:: (`List<String>`, default `[]`) Only consider tags matching the given glob(7) pattern, excluding the "refs/tags/" prefix. This can be used to avoid leaking private tags from the repository. If multiple patterns are given they will be accumulated, and tags matching any of the patterns will be considered.

== Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ class DescribeOp implements Callable<String> {
*/
boolean longDescr

/**
* glob patterns to match tags against before they are considered
*/
List<String> match = []

String call(){
DescribeCommand cmd = repo.jgit.describe()
if (commit) {
cmd.setTarget(new ResolveService(repo).toRevisionString(commit))
}
cmd.setLong(longDescr)
if (match) {
cmd.setMatch(match as String[])
}
return cmd.call()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class DescribeOpSpec extends SimpleGitOpSpec {
def setup() {
grgit.commit(message:"initial commit")
grgit.tag.add(name:"initial")
grgit.commit(message:"another commit")
grgit.tag.add(name:"another")
}

def 'with initial tag'() {
def 'with tag'() {
expect:
grgit.describe() == "initial"
grgit.describe() == "another"
}

def 'with additional commit'(){
Expand All @@ -34,7 +36,7 @@ class DescribeOpSpec extends SimpleGitOpSpec {
grgit.add(patterns:['1.txt'])
grgit.commit(message: "another commit")
then:
grgit.describe().startsWith("initial-1-")
grgit.describe().startsWith("another-1-")
}

def 'from differnt commit'(){
Expand All @@ -43,11 +45,16 @@ class DescribeOpSpec extends SimpleGitOpSpec {
grgit.add(patterns:['1.txt'])
grgit.commit(message: "another commit")
then:
grgit.describe(commit: 'HEAD^') == "initial"
grgit.describe(commit: 'HEAD~2') == "initial"
}

def 'with long description'() {
expect:
grgit.describe(longDescr: true).startsWith("initial-0-")
grgit.describe(longDescr: true).startsWith("another-0-")
}

def 'with match'() {
expect:
grgit.describe(match: ['initial*']).startsWith("initial-1-")
}
}

0 comments on commit dcc4872

Please sign in to comment.