Skip to content

Commit aca0874

Browse files
committed
Makefile: fix the "built from commit" code
In ed32b78 (version --build-options: report commit, too, if possible, 2017-12-15), we introduced code to let `git version --build-options` report the current commit from which the binaries were built, if any. To prevent erroneous commits from being reported (e.g. when unpacking Git's source code from a .tar.gz file into a subdirectory of a different Git project, as e.g. git_osx_installer does), we painstakingly set GIT_CEILING_DIRECTORIES when trying to determine the current commit. Except that we got the quoting wrong, and that variable therefore does not have the desired effect. The issue is that the $(shell) is resolved before the output is stuffed into the command-line with -DGIT_BUILT_FROM_COMMIT, and therefore is *not* inside quotes. And thus backslashing the quotes is wrong, as the quote gets literally inserted into the CEILING_DIRECTORIES variable. Let's fix that quoting, and while at it, also suppress the unhelpful message fatal: not a git repository (or any of the parent directories): .git that gets printed to stderr if no current commit could be determined, and might scare the occasional developer who simply tries to build Git from scratch. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e333175 commit aca0874

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,8 +2021,9 @@ version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
20212021
version.sp version.s version.o: EXTRA_CPPFLAGS = \
20222022
'-DGIT_VERSION="$(GIT_VERSION)"' \
20232023
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
2024-
'-DGIT_BUILT_FROM_COMMIT="$(shell GIT_CEILING_DIRECTORIES=\"$(CURDIR)/..\" \
2025-
git rev-parse -q --verify HEAD || :)"'
2024+
'-DGIT_BUILT_FROM_COMMIT="$(shell \
2025+
GIT_CEILING_DIRECTORIES="$(CURDIR)/.." \
2026+
git rev-parse -q --verify HEAD 2>/dev/null)"'
20262027

20272028
$(BUILT_INS): git$X
20282029
$(QUIET_BUILT_IN)$(RM) $@ && \

0 commit comments

Comments
 (0)