From 4a8a9a18117fb989696608132bd06f2ebcb478d7 Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Sat, 11 Jan 2025 21:31:17 +0100 Subject: [PATCH] build.gradle: correctly determine git directory in case the repo is used as a submodule --- build.gradle | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b19c9c6c..a9ac198b 100644 --- a/build.gradle +++ b/build.gradle @@ -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 {