@@ -18,6 +18,7 @@ package com.palantir.gradle.gitversion
18
18
import org.eclipse.jgit.api.Git
19
19
import org.eclipse.jgit.api.MergeCommand
20
20
import org.eclipse.jgit.lib.Ref
21
+ import org.eclipse.jgit.revwalk.RevCommit
21
22
import org.gradle.testkit.runner.BuildResult
22
23
import org.gradle.testkit.runner.GradleRunner
23
24
import org.junit.Rule
@@ -159,6 +160,27 @@ class GitVersionPluginTests extends Specification {
159
160
buildResult. output. contains(" :printVersion\n 1.0.0\n " )
160
161
}
161
162
163
+ def ' git describe when lightweight tag is present' () {
164
+ given :
165
+ buildFile << '''
166
+ plugins {
167
+ id 'com.palantir.git-version'
168
+ }
169
+ version gitVersion()
170
+ ''' . stripIndent()
171
+ gitIgnoreFile << ' build'
172
+ Git git = Git . init(). setDirectory(projectDir). call();
173
+ git. add(). addFilepattern(' .' ). call()
174
+ git. commit(). setMessage(' initial commit' ). call()
175
+ git. tag(). setAnnotated(false ). setName(' 1.0.0' ). call()
176
+
177
+ when :
178
+ BuildResult buildResult = with(' printVersion' ). build()
179
+
180
+ then :
181
+ buildResult. output. contains(" :printVersion\n 1.0.0\n " )
182
+ }
183
+
162
184
def ' git describe when annotated tag is present with merge commit' () {
163
185
given :
164
186
buildFile << '''
@@ -442,6 +464,56 @@ class GitVersionPluginTests extends Specification {
442
464
buildResult. output =~ " :printVersionDetails\n 1.0.0\n "
443
465
}
444
466
467
+ def ' git describe with commit after annotated tag' () {
468
+ given :
469
+ buildFile << '''
470
+ plugins {
471
+ id 'com.palantir.git-version'
472
+ }
473
+ version gitVersion()
474
+ ''' . stripIndent()
475
+ gitIgnoreFile << ' build'
476
+ Git git = Git . init(). setDirectory(projectDir). call();
477
+ git. add(). addFilepattern(' .' ). call()
478
+ git. commit(). setMessage(' initial commit' ). call()
479
+ git. tag(). setAnnotated(true ). setMessage(' 1.0.0' ). setName(' 1.0.0' ). call()
480
+ dirtyContentFile << ' dirty-content'
481
+ git. add(). addFilepattern(' .' ). call()
482
+ RevCommit latestCommit = git. commit(). setMessage(' added some stuff' ). call()
483
+
484
+ when :
485
+ BuildResult buildResult = with(' printVersion' ). build()
486
+ String commitSha = latestCommit. getName()
487
+
488
+ then :
489
+ buildResult. output. contains(" :printVersion\n 1.0.0-1-g${ commitSha.substring(0, 7)} \n " )
490
+ }
491
+
492
+ def ' git describe with commit after lightweight tag' () {
493
+ given :
494
+ buildFile << '''
495
+ plugins {
496
+ id 'com.palantir.git-version'
497
+ }
498
+ version gitVersion()
499
+ ''' . stripIndent()
500
+ gitIgnoreFile << ' build'
501
+ Git git = Git . init(). setDirectory(projectDir). call();
502
+ git. add(). addFilepattern(' .' ). call()
503
+ git. commit(). setMessage(' initial commit' ). call()
504
+ git. tag(). setAnnotated(false ). setName(' 1.0.0' ). call()
505
+ dirtyContentFile << ' dirty-content'
506
+ git. add(). addFilepattern(' .' ). call()
507
+ RevCommit latestCommit = git. commit(). setMessage(' added some stuff' ). call()
508
+
509
+ when :
510
+ BuildResult buildResult = with(' printVersion' ). build()
511
+ String commitSha = latestCommit. getName()
512
+
513
+ then :
514
+ buildResult. output. contains(" :printVersion\n 1.0.0-1-g${ commitSha.substring(0, 7)} \n " )
515
+ }
516
+
445
517
def ' test valid prefixes' () {
446
518
expect :
447
519
GitVersionPlugin . verifyPrefix(" @Product@" )
0 commit comments