From 3cd05f053062efd8b50d294df8aedef0f5eadbf7 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Mon, 30 Oct 2023 16:21:54 -0700 Subject: [PATCH] Check if a tag or branch is checked out by Antora --- build.gradle | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 70243992bb..4c9f54127f 100644 --- a/build.gradle +++ b/build.gradle @@ -38,10 +38,13 @@ buildscript { // TODO: remove these hacks once jgit supports worktrees (nebula upgrades) and/or Antora supports full-clone if (project.hasProperty('antora')) { 'git fetch --unshallow --all --tags'.execute().text // Antora shallow-clones so there is no history (we need commit history to find the last tag in the tree) - String tag = 'git tag --points-at HEAD'.execute().text.trim() // jgit does not able to figure out tags in Antora's worktree - if (tag) { - println "Found release tag: $tag, using it as release.version" - ext['release.version'] = tag.substring(1) + String ref = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim() + if (ref == 'HEAD') { // if Antora checks out a tag instead of a branch + String tag = 'git tag --points-at HEAD'.execute().text.trim() // jgit does not able to figure out tags in Antora's worktree + if (tag) { + println "Found release tag: $tag, using it as release.version" + ext['release.version'] = tag.substring(1) + } } // We need to tell the location of the .git folder since jgit does not support worktrees ext['git.root'] = 'git rev-parse --path-format=absolute --git-common-dir'.execute().text.trim()