Skip to content

Commit 084d2fa

Browse files
committed
Makefile: allow specifying GIT_BUILT_FROM_COMMIT
Allow specification of a custom `GIT_BUILT_FROM_COMMIT` string to replace the output of `git rev-parse HEAD`. This allows a build of `git` from somewhere other than an active clone of `git` (e.g. from the archive created with `make dist`) to include commit information in `git version --build-options`. Signed-off-by: Victoria Dye <vdye@github.com>
1 parent 672a6a7 commit 084d2fa

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/fuzz_corpora
22
/GIT-BUILD-DIR
33
/GIT-BUILD-OPTIONS
4+
/GIT-BUILT-FROM-COMMIT
45
/GIT-CFLAGS
56
/GIT-LDFLAGS
67
/GIT-PREFIX

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ include shared.mak
321321
# Define GIT_USER_AGENT if you want to change how git identifies itself during
322322
# network interactions. The default is "git/$(GIT_VERSION)".
323323
#
324+
# Define GIT_BUILT_FROM_COMMIT if you want to force the commit hash identified
325+
# in 'git version --build-options' to a specific value. The default is the
326+
# commit hash of the current HEAD.
327+
#
324328
# Define DEFAULT_HELP_FORMAT to "man", "info" or "html"
325329
# (defaults to "man") if you want to have a different default when
326330
# "git help" is called without a parameter specifying the format.
@@ -2363,6 +2367,15 @@ GIT-USER-AGENT: FORCE
23632367
echo '$(GIT_USER_AGENT_SQ)' >GIT-USER-AGENT; \
23642368
fi
23652369

2370+
GIT_BUILT_FROM_COMMIT = $(eval GIT_BUILT_FROM_COMMIT := $$(shell \
2371+
GIT_CEILING_DIRECTORIES="$$(CURDIR)/.." \
2372+
git rev-parse -q --verify HEAD 2>/dev/null))$(GIT_BUILT_FROM_COMMIT)
2373+
GIT-BUILT-FROM-COMMIT: FORCE
2374+
@if test x'$(GIT_BUILT_FROM_COMMIT)' != x"`cat GIT-BUILT-FROM-COMMIT 2>/dev/null`" ; then \
2375+
echo >&2 " * new built-from commit"; \
2376+
echo '$(GIT_BUILT_FROM_COMMIT)' >GIT-BUILT-FROM-COMMIT; \
2377+
fi
2378+
23662379
ifdef DEFAULT_HELP_FORMAT
23672380
BASIC_CFLAGS += -DDEFAULT_HELP_FORMAT='"$(DEFAULT_HELP_FORMAT)"'
23682381
endif
@@ -2477,13 +2490,11 @@ PAGER_ENV_CQ_SQ = $(subst ','\'',$(PAGER_ENV_CQ))
24772490
pager.sp pager.s pager.o: EXTRA_CPPFLAGS = \
24782491
-DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'
24792492

2480-
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
2493+
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT GIT-BUILT-FROM-COMMIT
24812494
version.sp version.s version.o: EXTRA_CPPFLAGS = \
24822495
'-DGIT_VERSION="$(GIT_VERSION)"' \
24832496
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
2484-
'-DGIT_BUILT_FROM_COMMIT="$(shell \
2485-
GIT_CEILING_DIRECTORIES="$(CURDIR)/.." \
2486-
git rev-parse -q --verify HEAD 2>/dev/null)"'
2497+
'-DGIT_BUILT_FROM_COMMIT="$(GIT_BUILT_FROM_COMMIT)"'
24872498

24882499
$(BUILT_INS): git$X
24892500
$(QUIET_BUILT_IN)$(RM) $@ && \

0 commit comments

Comments
 (0)