Skip to content

Commit eace4b0

Browse files
pks-tgitster
authored andcommitted
GIT-VERSION-GEN: fix overriding version via environment
GIT-VERSION-GEN tries to derive the version that Git is being built from via multiple different sources in the following order: 1. A file called "version" in the source tree's root directory, if it exists. 2. The current commit in case Git is built from a Git repository. 3. Otherwise, we use a fallback version stored in a variable which is bumped whenever a new Git version is getting tagged. It used to be possible to override the version by overriding the `GIT_VERSION` Makefile variable (e.g. `make GIT_VERSION=foo`). This worked somewhat by chance, only: `GIT-VERSION-GEN` would write the actual Git version into `GIT-VERSION-FILE`, not the overridden value, but when including the file into our Makefile we would not override the `GIT_VERSION` variable because it has already been set by the user. And because our Makefile used the variable to propagate the version to our build tools instead of using `GIT-VERSION-FILE` the resulting build artifacts used the overridden version. But that subtle mechanism broke with 4838dea (Makefile: refactor GIT-VERSION-GEN to be reusable, 2024-12-06) and subsequent commits because the version information is not propagated via the Makefile variable anymore, but instead via the files that `GIT-VERSION-GEN` started to write. And as the script never knew about the `GIT_VERSION` environment variable in the first place it uses one of the values listed above instead of the overridden value. Fix this issue by making `GIT-VERSION-GEN` handle the case where `GIT_VERSION` has been set via the environment. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 904339e commit eace4b0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

GIT-VERSION-GEN

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export GIT_CEILING_DIRECTORIES
2929

3030
# First see if there is a version file (included in release tarballs),
3131
# then try git-describe, then default.
32-
if test -f "$SOURCE_DIR"/version
32+
if test -n "$GIT_VERSION"
33+
then
34+
VN="$GIT_VERSION"
35+
elif test -f "$SOURCE_DIR"/version
3336
then
3437
VN=$(cat "$SOURCE_DIR"/version) || VN="$DEF_VER"
3538
elif {

0 commit comments

Comments
 (0)