GIT-VERSION-GEN: fix overriding GIT_BUILT_FROM_COMMIT and GIT_DATE

Same as with the preceding commit, neither GIT_BUILT_FROM_COMMIT nor GIT_DATE can be overridden via the environment. Especially the latter is of importance given that we set it in our own "Documentation/doc-diff" script. Make the values of both variables overridable. Luckily we don't pull in these values via any included Makefiles, so the fix is trivial compared to the fix for GIT_VERSON. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 20, 2024 at 20:44 UTC cfa01e6da515e409fdeaf39e50e8c3b7a70405b9
2 files changed +12 -2
GIT-VERSION-GEN
+10 -2
@@ -56,8 +56,16 @@ then
56 GIT_VERSION=$(expr "$VN" : v*'\(.*\)')
57 fi
58
59 -GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
60 -GIT_DATE=$(git -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/null)
59 +if test -z "$GIT_BUILT_FROM_COMMIT"
60 +then
61 + GIT_BUILT_FROM_COMMIT=$(git -C "$SOURCE_DIR" rev-parse -q --verify HEAD 2>/dev/null)
62 +fi
63 +
64 +if test -z "$GIT_DATE"
65 +then
66 + GIT_DATE=$(git -C "$SOURCE_DIR" show --quiet --format='%as' 2>/dev/null)
67 +fi
68 +
69 if test -z "$GIT_USER_AGENT"
70 then
71 GIT_USER_AGENT="git/$GIT_VERSION"
shared.mak
+2
@@ -121,6 +121,8 @@ endef
121 # absolute path to the root source directory as well as input and output files
122 # as arguments, in that order.
123 define version_gen
124 +GIT_BUILT_FROM_COMMIT="$(GIT_BUILT_FROM_COMMIT)" \
125 +GIT_DATE="$(GIT_DATE)" \
126 GIT_USER_AGENT="$(GIT_USER_AGENT)" \
127 GIT_VERSION="$(GIT_VERSION_OVERRIDE)" \
128 $(SHELL_PATH) "$(1)/GIT-VERSION-GEN" "$(1)" "$(2)" "$(3)"