Skip to content

Commit 2866f53

Browse files
committed
fix(hooks): scrub only repo-local git env in test lanes
Stripping every GIT_* var also removed caller transport/credential settings (GIT_SSH_COMMAND, GIT_ASKPASS, GIT_TERMINAL_PROMPT), which the branch-skew fetch needs and whose failure it tolerates silently. The wrapper now unsets only `git rev-parse --local-env-vars`, and the fixture-free branch-skew/push-head-scope guard lanes run unwrapped. Signed-off-by: Will Pfleger <[email protected]>
1 parent 573dcd8 commit 2866f53

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

‎lefthook.yml‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,23 @@ commit-msg:
7575
signoff:
7676
run: 'git interpret-trailers --if-exists doNothing --trailer "Signed-off-by: $(git var GIT_COMMITTER_IDENT | sed ''s/ [0-9]* [+-][0-9]*$//'')" --in-place {1}'
7777

78-
# Git exports repository-local variables (GIT_DIR, GIT_INDEX_FILE, ...) into
79-
# hook processes. Lanes below run test suites whose fixtures spawn git in temp
80-
# dirs, so every lane runs through scripts/without-git-env.sh, which strips
81-
# those variables and lets each subprocess rediscover the repo from its cwd.
78+
# Lanes below that run test suites or builds go through
79+
# scripts/without-git-env.sh, which strips git's repository-local variables
80+
# (per `git rev-parse --local-env-vars`) while preserving transport/credential
81+
# settings. The branch-skew and push-head-scope guards run no test fixtures
82+
# and need the caller's transport env, so they run unwrapped.
8283
pre-push:
8384
parallel: true
8485
commands:
8586
branch-skew:
86-
run: ./scripts/without-git-env.sh ./scripts/check-branch-skew.sh
87+
run: ./scripts/check-branch-skew.sh
8788
push-head-scope:
8889
# Warn-only: the scoped lanes below validate the checked-out HEAD, so a
8990
# non-HEAD ref push (explicit refspec, --all) relies on CI for its
9091
# path-scoped checks. This lane reads the pushed refs from stdin and
9192
# warns when any pushed commit is not HEAD. It never fails the push.
9293
use_stdin: true
93-
run: ./scripts/without-git-env.sh ./scripts/check-push-head-scope.sh
94+
run: ./scripts/check-push-head-scope.sh
9495
file-size-check:
9596
# The ratchet computes its own merge-base diff, so path filtering here
9697
# would only duplicate policy and create another place for coverage drift.

‎scripts/without-git-env.sh‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/usr/bin/env bash
2-
# Git exports repository-local variables (GIT_DIR, GIT_INDEX_FILE,
3-
# GIT_WORK_TREE, ...) to hooks. Pre-push lanes run test suites whose fixtures
4-
# spawn git in temp dirs; with those variables inherited, fixtures operate on
5-
# this checkout instead. Lanes rediscover the repository from their working
6-
# directory.
2+
# Git exports repository-local variables (GIT_DIR, GIT_INDEX_FILE, ...) to
3+
# hooks. Pre-push lanes run test suites whose fixtures spawn git in temp dirs;
4+
# with those variables inherited, fixtures operate on this checkout instead.
5+
# Transport, credential, and TLS settings (GIT_SSH_COMMAND, GIT_ASKPASS, ...)
6+
# are left intact.
77
set -euo pipefail
8-
9-
for var in $(env | sed -n 's/^\(GIT_[A-Za-z0-9_]*\)=.*/\1/p'); do
10-
unset "$var"
11-
done
12-
8+
# shellcheck disable=SC2046
9+
unset $(git rev-parse --local-env-vars)
1310
exec "$@"

0 commit comments

Comments
 (0)