From 8813eb99e5b0df3b09c945f004199f201c35ba80 Mon Sep 17 00:00:00 2001 From: Johannes Schnatterer Date: Fri, 13 Mar 2020 14:03:37 +0100 Subject: [PATCH] Removes trailing caret from git.tag --- README.md | 5 +++-- src/com/cloudogu/ces/cesbuildlib/Git.groovy | 5 +++-- test/com/cloudogu/ces/cesbuildlib/GitTest.groovy | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7109a42e..b300fd96 100644 --- a/README.md +++ b/README.md @@ -465,8 +465,9 @@ gitWithCreds 'https://your.repo' // Implicitly passed credentials * `git.commitHashShort` - e.g. `fb1c882` * `git.repositoryUrl` - e.g. `https://github.com/orga/repo.git` * `git.gitHubRepositoryName` - e.g. `orga/repo` -* `git.tag` - e.g. `1.0.0` or `undefined` if not set -* `git.isTag()` - is there a tag on the current commit? +* Tags - Note that the git plugin might not fetch tags for all builds. Run `sh "git fetch --tags"` to make sure. + * `git.tag` - e.g. `1.0.0` or `undefined` if not set + * `git.isTag()` - is there a tag on the current commit? ### Changes to local repository diff --git a/src/com/cloudogu/ces/cesbuildlib/Git.groovy b/src/com/cloudogu/ces/cesbuildlib/Git.groovy index d441ddcf..58df1ef3 100644 --- a/src/com/cloudogu/ces/cesbuildlib/Git.groovy +++ b/src/com/cloudogu/ces/cesbuildlib/Git.groovy @@ -128,11 +128,12 @@ class Git implements Serializable { } String getTag() { - return sh.returnStdOut("git name-rev --name-only --tags HEAD") + // Note that "git name-rev --name-only --tags HEAD" always seems to append a caret (e.g. "1.0.0^") + return sh.returnStdOut("git tag --points-at HEAD") } boolean isTag() { - return getTag() != "undefined" + return !getTag().isEmpty() } def add(String pathspec) { diff --git a/test/com/cloudogu/ces/cesbuildlib/GitTest.groovy b/test/com/cloudogu/ces/cesbuildlib/GitTest.groovy index 2abc68dc..b8c4f0d5 100644 --- a/test/com/cloudogu/ces/cesbuildlib/GitTest.groovy +++ b/test/com/cloudogu/ces/cesbuildlib/GitTest.groovy @@ -183,7 +183,7 @@ class GitTest { @Test void isNotATag() { - String expectedReturnValue = "undefined" + String expectedReturnValue = "" scriptMock.expectedDefaultShRetValue = expectedReturnValue + " \n" assertFalse(git.isTag()) }