File tree 1 file changed +12
-12
lines changed
1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -65,8 +65,8 @@ val gitDescribe: Provider<String> =
65
65
" describe" ,
66
66
" --always" ,
67
67
" --tags" ,
68
- " --dirty=-SNAPSHOT " ,
69
- " --broken=-SNAPSHOT " ,
68
+ " --dirty=-DIRTY " ,
69
+ " --broken=-BROKEN " ,
70
70
" --match=v[0-9]*\\ .[0-9]*\\ .[0-9]*" ,
71
71
)
72
72
isIgnoreExitValue = true
@@ -96,21 +96,21 @@ val currentCommitHash: Provider<String> =
96
96
isIgnoreExitValue = true
97
97
}.standardOutput.asText.map { it.trim() }
98
98
99
+ val semverRegex = Regex (""" v[0-9]+\.[0-9]+\.[0-9]+""" )
100
+
99
101
val gitVersion: Provider <String > =
100
102
gitDescribe.zip(currentBranchName) { described, branch ->
101
- val snapshot = if (" SNAPSHOT" in described) " -SNAPSHOT" else " "
102
-
103
- val descriptions = described.split(" -" )
103
+ val detached = branch.isNullOrBlank()
104
104
105
- if (branch.isNullOrBlank() && descriptions.size in 1 .. 2 ) {
106
- // detached if there's no current branch, or if 'git described' indicates additional commits
107
- val tag = descriptions.getOrNull(0 )
108
- " $tag$snapshot "
105
+ if (! detached) {
106
+ " $branch -SNAPSHOT"
109
107
} else {
110
- // current commit is attached
111
- " $branch$snapshot "
108
+ val descriptions = described.split(" -" )
109
+ val head = descriptions.singleOrNull() ? : " "
110
+ val headIsVersioned = head.matches(semverRegex)
111
+ if (headIsVersioned) head else " $branch -SNAPSHOT"
112
112
}
113
- }.orElse(currentCommitHash)
113
+ }.orElse(currentCommitHash) // fall back to using the git commit hash
114
114
115
115
gradle.allprojects {
116
116
extensions.add<Provider <String >>(" gitVersion" , gitVersion)
You can’t perform that action at this time.
0 commit comments