fix: gstack-repo-mode handles repos without origin remote

Fall back through origin/main → origin/master → HEAD when
git symbolic-ref refs/remotes/origin/HEAD is not set. Prevents
shortlog crash in repos where origin/HEAD isn't configured.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-21 10:05:24 -07:00
parent 74add1503a
commit 700e024a4a
+11 -1
View File
@@ -46,7 +46,17 @@ fi
# Compute from git history (90-day window)
# Use default branch (not HEAD) to avoid feature-branch sampling bias
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/||' || echo "origin/main")
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/||' || true)
# Fallback: try origin/main, then origin/master, then HEAD
if [ -z "$DEFAULT_BRANCH" ]; then
if git rev-parse --verify origin/main &>/dev/null; then
DEFAULT_BRANCH="origin/main"
elif git rev-parse --verify origin/master &>/dev/null; then
DEFAULT_BRANCH="origin/master"
else
DEFAULT_BRANCH="HEAD"
fi
fi
SHORTLOG=$(git shortlog -sn --since="90 days ago" --no-merges "$DEFAULT_BRANCH" 2>/dev/null | head -20)
if [ -z "$SHORTLOG" ]; then
echo "REPO_MODE=unknown"