Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for git describe --abbrev #373

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/modules/ROOT/pages/grgit-describe.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ grgit.describe()

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

[source, groovy]
Expand All @@ -24,6 +24,7 @@ grgit.describe {
tags = <boolean>
match = [<string>]
always = <boolean>
abbrev = <Integer>
}
----

Expand All @@ -40,6 +41,7 @@ always:: (`boolean`, default `false`) When `true`, always describe a commit in s
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…​.).
tags:: (`boolean`, default `false`) Instead of using only the annotated tags, use any tag found in `refs/tags` namespace. This option enables matching a lightweight (non-annotated) tag.
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.
abbrev:: (`Integer`, default `null`) Instead of using the default number of hexadecimal digits (which will vary according to the number of objects in the repository with a default of 7) of the abbreviated object name, use <n> digits, or as many digits as needed to form a unique object name. An <n> of 0 will suppress long format, only showing the closest tag.

== Examples

Expand All @@ -64,6 +66,12 @@ Always output the long format (the tag, the number of commits and the abbreviate
grgit.describe(longDescr: true) == '2.0.0-rc.1-7-g91fda36'
----

Abbreviate object name to at least 2 digits, or as many digits as needed to form a unique object name.

[source, groovy]
----
grgit.describe(abbrev: 2) == '2.0.0-rc.1-7-g91fd'
----

== See Also

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class DescribeOp implements Callable<String> {
*/
List<String> match = []

/**
* Abbreviate resulting object name to use at least n hexadecimal digits
*/
Integer abbrev

String call(){
DescribeCommand cmd = repo.jgit.describe()
if (commit) {
Expand All @@ -57,6 +62,9 @@ class DescribeOp implements Callable<String> {
if (match) {
cmd.setMatch(match as String[])
}
if(abbrev != null) {
cmd.setAbbrev(abbrev)
}
return cmd.call()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ class DescribeOpSpec extends SimpleGitOpSpec {
expect:
grgit.describe(match: ['second*']).startsWith('second-2-')
}

def 'with abbrev'() {
expect:
grgit.describe(abbrev: abbrev) ==~ expectedPattern

where:
abbrev | expectedPattern
0 | /^another$/
30 | /^another-1-g.{30}$/
}
}