]> git.kaiwu.me - haproxy.git/commitdiff
BUILD: makefile: better support git worktrees
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Oct 2026 18:27:51 +0000 (20:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 Oct 2026 19:24:41 +0000 (21:24 +0200)
Git worktrees replace the .git directory with a file which contains the
location to the git directory. The version generation test is based on
the detection of .git/. as a directory, and thus fails inside a worktree.
Let's relax the test to only see if .git exists.

Makefile

index 2d3dcee33f195ed887f9014538f15a7985078317..6bb0ff353765909ec78f6a2f73002041ab6a245c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -540,7 +540,7 @@ endif
 # holding the same names in the current directory.
 
 ifeq ($(IGNOREGIT),)
-  VERSION := $(shell [ -d .git/. ] && (git describe --tags --match 'v*' --abbrev=0 | cut -c 2-) 2>/dev/null)
+  VERSION := $(shell [ -e .git ] && (git describe --tags --match 'v*' --abbrev=0 | cut -c 2-) 2>/dev/null)
   ifneq ($(VERSION),)
     # OK git is there and works.
     SUBVERS := $(shell comms=`git log --format=oneline --no-merges v$(VERSION).. 2>/dev/null | wc -l | tr -d '[:space:]'`; commit=`(git log -1 --pretty=%h --abbrev=6) 2>/dev/null`; [ $$comms -gt 0 ] && echo "-$$commit-$$comms")
@@ -1409,7 +1409,7 @@ unit-tests:
 # failure.
 
 range:
-       $(Q)[ -d .git/. ] || { echo "## Fatal: \"make $@\" may only be used inside a Git repository."; exit 1; }
+       $(Q)[ -e .git ] || { echo "## Fatal: \"make $@\" may only be used inside a Git repository."; exit 1; }
 
        $(Q)if git diff-index --name-only HEAD 2>/dev/null | grep -q ^; then \
                echo "Fatal: \"make $@\" requires a clean working tree."; exit 1; fi