From ccc24971f78f33d9a9cb63ae277882ae43c35b3f Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 18 Oct 2023 17:28:14 -0400 Subject: [PATCH] Fix: make gen-version-i.sh work with shallow clones With a shallow git clone (a clone done with `--depth=1`), gen-version-i.sh fails with: $ TOP_SRCDIR=$PWD ./src/common/gen-version-i.sh fatal: No names found, cannot describe anything. The underlying git command that fails is: $ git describe --tags --dirty --abbrev=12 fatal: No names found, cannot describe anything. git-describe fails because no tags are available in the shallow clone. Work around that by using `--always`, which makes git-describe generate string with only the commit hash as a fallback. In my non-shallow clone: $ git describe --tags --dirty --abbrev=12 --always v1.2.0-3854-g0b538efadd88 And in my shallow clone: $ git describe --tags --dirty --abbrev=12 --always 0b538efadd88 Change-Id: Ie1c15239497bda248c9742e74a12a14af6e32928 Signed-off-by: Simon Marchi Signed-off-by: Thomas Applencourt Reviewed-on: https://review.lttng.org/c/babeltrace/+/11073 Reviewed-by: Philippe Proulx CI-Build: Philippe Proulx Reviewed-by: Michael Jeanson Tested-by: jenkins --- src/common/gen-version-i.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/gen-version-i.sh b/src/common/gen-version-i.sh index 938d70c5..a53593cd 100755 --- a/src/common/gen-version-i.sh +++ b/src/common/gen-version-i.sh @@ -42,7 +42,7 @@ fi # configurations leading to different results. if test -r "$TOP_SRCDIR/bootstrap" && test -r "$TOP_SRCDIR/.git" && (command -v git > /dev/null 2>&1); then - GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && git describe --tags --dirty --abbrev=12)" + GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && git describe --always --tags --dirty --abbrev=12)" GIT_CURRENT_TAG="$(cd "$TOP_SRCDIR" && (git describe --tags --exact-match --match="v[0-9]*" HEAD || true) 2> /dev/null)" echo "#define BT_VERSION_GIT \"$GIT_VERSION_STR\"" > version.i.tmp -- 2.34.1