mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-19 02:42:29 +08:00
fix: gstack-repo-mode handles repos without origin remote
Split `git remote get-url origin` into a separate variable with `|| true` so the script doesn't crash under `set -euo pipefail` in local-only repos. Falls back to REPO_MODE=unknown gracefully. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,12 @@ set -euo pipefail
|
|||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
# Compute SLUG directly (avoid eval of gstack-slug — branch names can contain shell metacharacters)
|
# Compute SLUG directly (avoid eval of gstack-slug — branch names can contain shell metacharacters)
|
||||||
SLUG=$(git remote get-url origin 2>/dev/null | sed 's|.*[:/]\([^/]*/[^/]*\)\.git$|\1|;s|.*[:/]\([^/]*/[^/]*\)$|\1|' | tr '/' '-')
|
REMOTE_URL=$(git remote get-url origin 2>/dev/null || true)
|
||||||
|
if [ -z "$REMOTE_URL" ]; then
|
||||||
|
echo "REPO_MODE=unknown"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
SLUG=$(echo "$REMOTE_URL" | sed 's|.*[:/]\([^/]*/[^/]*\)\.git$|\1|;s|.*[:/]\([^/]*/[^/]*\)$|\1|' | tr '/' '-')
|
||||||
[ -z "${SLUG:-}" ] && { echo "REPO_MODE=unknown"; exit 0; }
|
[ -z "${SLUG:-}" ] && { echo "REPO_MODE=unknown"; exit 0; }
|
||||||
|
|
||||||
# Validate: only allow known values (prevent shell injection via source <(...))
|
# Validate: only allow known values (prevent shell injection via source <(...))
|
||||||
|
|||||||
Reference in New Issue
Block a user