From 333bb82c162860ec39e0e5ed926a91c0754a548c Mon Sep 17 00:00:00 2001 From: Bot Date: Wed, 9 Sep 2026 14:01:26 -0700 Subject: [PATCH] fix(git-guard): use 'exec bash "$0"' instead of 'exec "$0"' for self-re-invocation Found via live testing on docker-2 after merging #19: git-guard.sh is tracked in git at mode 100644 (not executable). stack-deploy.sh correctly invokes it as `bash deploy/git-guard.sh`, sidestepping the exec bit for the first call -- but the script's own internal `exec "$0" "$@"` calls (used to cleanly re-run after a successful push or stash-pop) rely on the kernel executing the file directly, which requires +x. Since every fresh checkout or fast-forward preserves the tracked 644 mode, this failed with "Permission denied" (exit 126) the moment either self-re-invocation path was actually exercised. Confirmed via a live dry run: simulated the exact #18 incident shape (dirty git-guard.sh on a HEAD 3 commits behind origin/main) on docker-2. The new stash-first logic from #19 worked perfectly end-to-end -- detected dirty+stale, stashed safely, fast-forwarded via resync_with_origin(), and popped the stash cleanly -- but then hit this pre-existing bug on the final `exec "$0" "$@"` re-invocation. This bug pre-dates #19 (the old dirty-commit-then-push-success path had the identical pattern); #19 just added a second trigger point that happened to surface it during testing. Fix: `exec bash "$0" "$@"` explicitly invokes through the interpreter instead of relying on the file's own execute bit -- correct regardless of what git tracks the file's mode as. --- deploy/git-guard.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/git-guard.sh b/deploy/git-guard.sh index 0426ce1..7b629c8 100644 --- a/deploy/git-guard.sh +++ b/deploy/git-guard.sh @@ -218,7 +218,7 @@ if [ "$DIRTY" -eq 1 ]; then echo "==> Resync succeeded. Reapplying stashed changes..." if git stash pop; then echo "==> Stash reapplied cleanly. Re-checking sync state..." - exec "$0" "$@" + exec bash "$0" "$@" else echo "ERROR: 'git stash pop' did not complete successfully." echo @@ -308,7 +308,7 @@ if [ "$DIRTY" -eq 1 ]; then if git push origin main; then echo "==> Pushed. Re-checking sync state..." - exec "$0" "$@" + exec bash "$0" "$@" else echo "ERROR: push failed (likely diverged from origin). Aborting deploy." echo "Run:"