nemerosa/versioning

lastTag is incorrectly calculated

Closed this issue · 0 comments

getLastTags in src/main/groovy/net/nemerosa/versioning/git/GitInfoService.groovy is returning the tags sorted in incorrect order.
The main criteria for sorting should be the tag commit time, and second criteria should be desc version, however it seems that the result of commit time based sort is ignored due to the chaining of calls to sort()

    @Override
    List<String> getLastTags(Project project, VersioningExtension extension, String tagPattern) {
        def grgit = Grgit.open(currentDir: getGitDirectory(extension, project))
        return grgit.tag.list()
                .findAll { (it.name =~ tagPattern).find() }
                .sort { -it.commit.time }
                .sort { -TagSupport.tagOrder(tagPattern, it.name) } // <-- second sort, overriding the first
                .collect { it.name }
    }

Example problematic scenario :

  • you have an old commit tagged as '1.2.16'
  • you have the most recent commit, tagged as '1.3.12'

./gradlew versionDisplay will return

[version] display     = 1.3.13
[version] tag         =
[version] lastTag     = 1.2.16

because 16 is bigger than 13 and because the commit time of 1.3.13 is ignored.

I'm already working on a fix for this, and I have written test scenarios so you can assign this issue to me