Skip to content

Commit

Permalink
build.gradle: correctly determine git directory in case the repo is u…
Browse files Browse the repository at this point in the history
…sed as a submodule
  • Loading branch information
bwRavencl committed Jan 11, 2025
1 parent 3dcf7ac commit 4a8a9a1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ plugins {
id 'org.gradlex.extra-java-module-info' version '1.9'
}

def git = Grgit.open(dir: projectDir)
def dotGitFile = new File("$projectDir/.git")
def gitDir
if (dotGitFile.isFile()) {
def gitDirConfigValue = dotGitFile.readLines().stream().mapMulti { line, downstream ->
def match = line =~ /^gitdir: (\S*)/
def value = match[0][1];
if (value) {
downstream.accept value
}
}.findFirst().orElseThrow({ new GradleException('gitdir not set') })
gitDir = "$projectDir/$gitDirConfigValue"
} else {
gitDir = projectDir
}

def git = Grgit.open dir: gitDir
version = "${git.describe(longDescr: true).replaceFirst('-', '.').replaceFirst('-g', '-')}${((!git.status().isClean()) ? '.dirty' : '')}"

base {
Expand Down

0 comments on commit 4a8a9a1

Please sign in to comment.