Fix: make gen-version-i.sh work with shallow clones
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 18 Oct 2023 21:28:14 +0000 (17:28 -0400)
committerMichael Jeanson <mjeanson@efficios.com>
Fri, 20 Oct 2023 15:36:04 +0000 (11:36 -0400)
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 <simon.marchi@efficios.com>
Signed-off-by: Thomas Applencourt <tapplencourt@anl.gov>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11073
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
src/common/gen-version-i.sh

index 938d70c59565e0e28847c83227bac761990961b5..a53593cd229c9b503053d7d913eeb04644cc7d1f 100755 (executable)
@@ -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
 
This page took 0.028363 seconds and 4 git commands to generate.