diff --git a/tests/test-check-release-needed.sh b/tests/test-check-release-needed.sh index 75d15e2..440960b 100755 --- a/tests/test-check-release-needed.sh +++ b/tests/test-check-release-needed.sh @@ -76,12 +76,21 @@ EOF # $3 is optional: pre-commit's PRE_COMMIT_TO_REF, the local sha being pushed. # Left off entirely, the variable stays unset and the script falls back to HEAD, # exactly as a plain `git push ` behaves. +# The fixture repo is the subject under test, so every PRE_COMMIT_* input must +# come from this function and nowhere else. Any such variable already in the +# environment belongs to the *caller's* repo: run under the pre-push hook this +# suite guards, PRE_COMMIT_TO_REF holds a sha of the real repo, which does not +# exist in the fixture, and the script resolves against the wrong rev. Clearing +# them is what makes a standalone run and a pre-push run the same test — this +# suite passed everywhere except under the hook it exists to protect. run_check() { local dir="$1" branch="$2" if [[ $# -ge 3 ]]; then - (cd "$dir" && PRE_COMMIT_REMOTE_BRANCH="$branch" PRE_COMMIT_TO_REF="$3" bash "$SCRIPT" 2>&1) + (cd "$dir" && unset PRE_COMMIT_FROM_REF \ + && PRE_COMMIT_REMOTE_BRANCH="$branch" PRE_COMMIT_TO_REF="$3" bash "$SCRIPT" 2>&1) else - (cd "$dir" && PRE_COMMIT_REMOTE_BRANCH="$branch" bash "$SCRIPT" 2>&1) + (cd "$dir" && unset PRE_COMMIT_FROM_REF PRE_COMMIT_TO_REF \ + && PRE_COMMIT_REMOTE_BRANCH="$branch" bash "$SCRIPT" 2>&1) fi }