gradle-git-version icon indicating copy to clipboard operation
gradle-git-version copied to clipboard

Inconsistent error when two prefixed and annotated tags point to the same commit

Open jfleck1 opened this issue 2 years ago • 1 comments

Setup: Gradle with Kotlin DSL and multiple subprojects, each with independent versioning

Symptom: When running a build, either in the command line or within IntelliJ, this error occurs:

Inconsistent git describe: native was [email protected] and jgit was 05e75f8.

This occurred when a single commit addresses issues in multiple gradle subprojects within the same git repository. This causes prefixed release tags for each subproject to be added to the same commit.

After stepping through the code, I found that the RefWithTagNameComparator wasn't comparing the tags correctly.

https://github.com/palantir/gradle-git-version/blob/c62bf60cbb5cb64a646afa7084ca4c8ccf69f8d0/src/main/java/com/palantir/gradle/gitversion/RefWithTagNameComparator.java#L46

The comparator then causes the incorrect ref to be added, or none at all, when trying to use updateCommitHashMap.

https://github.com/palantir/gradle-git-version/blob/8b81ba6b4c9e274564c8f7b4c236bd20e22546a6/src/main/java/com/palantir/gradle/gitversion/JGitDescribe.java#L122

Because updateCommitHashMap fails to add the commit to the map, commitHashToTag doesn't contain the correct tag.

https://github.com/palantir/gradle-git-version/blob/8b81ba6b4c9e274564c8f7b4c236bd20e22546a6/src/main/java/com/palantir/gradle/gitversion/JGitDescribe.java#L53

Solution Idea Possibly refactor how the commit hash to tag loading works so that the full tag name is used instead. Because multiple tags can point to the same commit hash, it makes sense to use the full /ref/tags listing since that is the unique listing.

Workaround: Avoid releasing and adding two tags to the same commit. In a multiple project structure, this makes sense... in a way. One subproject's fixes and commits should be independent of the other subproject's. Write more succinct and focused commits, one per subproject.

jfleck1 avatar May 23 '22 18:05 jfleck1