From 83bdf3830e0db3bfb8a062351070c47a6d8fc817 Mon Sep 17 00:00:00 2001 From: Collin Straka Date: Fri, 27 Mar 2026 00:12:35 -0700 Subject: [PATCH] fix: fall back to dirname/unknown when git context is absent gstack-review-log uses set -euo pipefail, which treats empty strings as unbound variables. When run outside a git repo (or in a repo with no remote), gstack-slug produced empty SLUG and BRANCH, causing: gstack-review-log: line 8: SLUG: unbound variable gstack-review-log: line 9: BRANCH: unbound variable Fix: add || true to prevent set -e from aborting on git failures, then fall back to the current directory name for SLUG and "unknown" for BRANCH. Co-Authored-By: Claude Sonnet 4.6 --- bin/gstack-slug | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/gstack-slug b/bin/gstack-slug index a7ae78839..e6411931a 100755 --- a/bin/gstack-slug +++ b/bin/gstack-slug @@ -6,10 +6,13 @@ # Security: output is sanitized to [a-zA-Z0-9._-] only, preventing # shell injection when consumed via source or eval. set -euo pipefail -RAW_SLUG=$(git remote get-url origin 2>/dev/null | sed 's|.*[:/]\([^/]*/[^/]*\)\.git$|\1|;s|.*[:/]\([^/]*/[^/]*\)$|\1|' | tr '/' '-') -RAW_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '/' '-') +RAW_SLUG=$(git remote get-url origin 2>/dev/null | sed 's|.*[:/]\([^/]*/[^/]*\)\.git$|\1|;s|.*[:/]\([^/]*/[^/]*\)$|\1|' | tr '/' '-' || true) +RAW_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '/' '-' || true) # Strip any characters that aren't alphanumeric, dot, hyphen, or underscore SLUG=$(printf '%s' "$RAW_SLUG" | tr -cd 'a-zA-Z0-9._-') BRANCH=$(printf '%s' "$RAW_BRANCH" | tr -cd 'a-zA-Z0-9._-') +# Fall back to directory name / "unknown" when git context is absent +SLUG="${SLUG:-$(basename "$PWD" | tr -cd 'a-zA-Z0-9._-')}" +BRANCH="${BRANCH:-unknown}" echo "SLUG=$SLUG" echo "BRANCH=$BRANCH"