KAFKA-14767: Fix missing commitId build error after git gc (#13315)

git gc moves commit hashes from individual .git/refs/heads/ to .git/packed-refs which is not read
by the determineCommitId function.

Replace the existing lookup within the .git directory with a GrGit lookup that handles packed and
unpacked refs transparently.

Reviewers: Ismael Juma <ismael@juma.me.uk>
This commit is contained in:
Greg Harris 2023-10-22 11:08:01 -07:00
parent e569b5d2c8
commit af228ca84f
1 changed files with 4 additions and 12 deletions

View File

@ -106,6 +106,7 @@ ext {
throw new GradleException("Unexpected value for scalaOptimizerMode property. Expected one of $scalaOptimizerValues, but received: $userScalaOptimizerMode")
generatedDocsDir = new File("${project.rootDir}/docs/generated")
repo = file("$rootDir/.git").isDirectory() ? Grgit.open(currentDir: project.getRootDir()) : null
commitId = determineCommitId()
}
@ -161,16 +162,8 @@ def determineCommitId() {
def takeFromHash = 16
if (project.hasProperty('commitId')) {
commitId.take(takeFromHash)
} else if (file("$rootDir/.git/HEAD").exists()) {
def headRef = file("$rootDir/.git/HEAD").text
if (headRef.contains('ref: ')) {
headRef = headRef.replaceAll('ref: ', '').trim()
if (file("$rootDir/.git/$headRef").exists()) {
file("$rootDir/.git/$headRef").text.trim().take(takeFromHash)
}
} else {
headRef.trim().take(takeFromHash)
}
} else if (repo != null) {
repo.head().id.take(takeFromHash)
} else {
"unknown"
}
@ -178,7 +171,7 @@ def determineCommitId() {
apply from: file('wrapper.gradle')
if (file('.git').exists()) {
if (repo != null) {
rat {
dependsOn subprojects.collect {
it.tasks.matching {
@ -192,7 +185,6 @@ if (file('.git').exists()) {
// Exclude everything under the directory that git should be ignoring via .gitignore or that isn't checked in. These
// restrict us only to files that are checked in or are staged.
def repo = Grgit.open(currentDir: project.getRootDir())
excludes = new ArrayList<String>(repo.clean(ignore: false, directories: true, dryRun: true))
// And some of the files that we have checked in should also be excluded from this check
excludes.addAll([