From 77f30202d05bdfd051b53f8f966df1e473a0010e Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Tue, 27 Jan 2026 13:23:21 +0000 Subject: [PATCH] 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 --- tools/version.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tools/version.sh b/tools/version.sh index 1863789917..dce5354387 100755 --- a/tools/version.sh +++ b/tools/version.sh @@ -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