@@ -19,10 +19,18 @@ set -u
1919JSON=0
2020[[ " ${1:- } " == " --json" ]] && JSON=1
2121
22- # Locate repo root (the dir that contains scripts/doctor.sh).
22+ # Locate repo root. Prefer `git rev-parse` so moving this script up or down
23+ # a directory level does not silently break path arithmetic. Fall back to the
24+ # legacy 4-levels-up relative path when not in a git checkout (e.g. extracted
25+ # tarball, or running outside the repo).
2326HERE=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
24- # .claude/skills/_shared/scripts/ -> repo root is 4 levels up.
25- REPO_ROOT=" $( cd " $HERE /../../../.." && pwd) "
27+ if command -v git > /dev/null 2>&1 \
28+ && REPO_ROOT=" $( git -C " $HERE " rev-parse --show-toplevel 2> /dev/null) " \
29+ && [[ -n " $REPO_ROOT " ]]; then
30+ :
31+ else
32+ REPO_ROOT=" $( cd " $HERE /../../../.." && pwd) "
33+ fi
2634
2735# ---------------------------------------------------------------------------
2836# Helpers
@@ -46,7 +54,9 @@ OS_KERNEL="$(uname -srm 2>/dev/null || echo unknown)"
4654OS_ID=" "
4755OS_VERSION=" "
4856if [[ -f /etc/os-release ]]; then
57+ # shellcheck source=/dev/null
4958 OS_ID=" $( . /etc/os-release && echo " ${ID:- } " ) "
59+ # shellcheck source=/dev/null
5060 OS_VERSION=" $( . /etc/os-release && echo " ${VERSION_ID:- } " ) "
5161fi
5262CPU_COUNT=" $( nproc 2> /dev/null || echo 0) "
@@ -194,8 +204,13 @@ BUILD_DIR_EXISTS=false
194204
195205SUBMODULES_JSON=' []'
196206if [[ -f " $REPO_ROOT /.gitmodules" ]] && command -v git > /dev/null 2>&1 ; then
207+ # Note: must use `python3 -c` rather than `python3 - <<HEREDOC` here,
208+ # because the heredoc redirect would override the piped stdin from
209+ # git submodule status and the script would never see any submodule
210+ # lines (silently emits '[]' regardless). Currently no submodules in
211+ # this repo, so the bug was latent until a future submodule lands.
197212 SUBMODULES_JSON=$( cd " $REPO_ROOT " && git submodule status 2> /dev/null \
198- | python3 - << ' PY '
213+ | python3 -c '
199214import json, sys
200215out = []
201216for line in sys.stdin:
@@ -211,8 +226,7 @@ for line in sys.stdin:
211226 "initialized": initialized,
212227 })
213228print(json.dumps(out))
214- PY
215- )
229+ ' )
216230fi
217231
218232# ---------------------------------------------------------------------------
0 commit comments