Skip to content

Commit

Permalink
Removes trailing caret from git.tag
Browse files Browse the repository at this point in the history
  • Loading branch information
schnatterer committed Mar 13, 2020
1 parent a5799c2 commit 8813eb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/com/cloudogu/ces/cesbuildlib/Git.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/com/cloudogu/ces/cesbuildlib/GitTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class GitTest {

@Test
void isNotATag() {
String expectedReturnValue = "undefined"
String expectedReturnValue = ""
scriptMock.expectedDefaultShRetValue = expectedReturnValue + " \n"
assertFalse(git.isTag())
}
Expand Down

0 comments on commit 8813eb9

Please sign in to comment.