tools: detect Git revision correctly in non-default worktrees

In a non-default Git worktree, the .git directory is replaced
by a file containing the path to the real .git directory. This
breaks the version detection logic because it expects .git to
be a directory.

Passing the root of the source tree via "git -C", letting Git
figure out if we're in a repo or not, solves this problem.

Change-Id: I595f1a694258cad490b1a4964f8ae9d51ae76de1
This commit is contained in:
Aidan MacDonald 2026-01-27 13:23:21 +00:00 committed by Solomon Peachy
parent 2b09078b92
commit 77f30202d0

View file

@ -19,16 +19,14 @@
# This logic is pulled from the Linux's scripts/setlocalversion (also GPL)
# and tweaked for rockbox.
gitversion() {
export GIT_DIR="$1/.git"
# This verifies we are in a git directory
if head=`git rev-parse --verify --short=10 HEAD 2>/dev/null`; then
if head=`git -C "$1" rev-parse --verify --short=10 HEAD 2>/dev/null`; then
# Are there uncommitted changes?
export GIT_WORK_TREE="$1"
if git diff --name-only HEAD | read dummy; then
if git -C "$1" diff --name-only HEAD | read dummy; then
mod="M"
elif git diff --name-only --cached HEAD | read dummy; then
elif git -C "$1" diff --name-only --cached HEAD | read dummy; then
mod="M"
fi
@ -51,9 +49,7 @@ if [ -z $VERSION ]; then
VER=`cat $TOP/$VERSIONFILE`;
else
# Ok, we need to derive it from the Version Control system
if [ -d "$TOP/.git" ]; then
VER=`gitversion $TOP`
fi
fi
VERSION=$VER-`date -u +%y%m%d`
fi