Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/scripts/git-hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ refs="$(cat 2>/dev/null || true)"
# from a pre-commit gate run would point the mutation leg at an empty diff.
unset MULL_DIFF_BASE
top="$(git rev-parse --show-toplevel)"
# Git exports its repository context to hooks. The gate creates fixture
# repositories; they must not inherit this worktree's GIT_DIR or index.
mapfile -t repository_environment < <(git rev-parse --local-env-vars)
unset "${repository_environment[@]}"
cd "$top" || exit 1

if [[ "${WEK_GATE_FORCE:-0}" != "1" && -f "$top/tools/scripts/lib/gate_marker.sh" ]]; then
cd "$top"
source tools/scripts/lib/gate_marker.sh
pushed=0
covered=1
Expand Down
18 changes: 18 additions & 0 deletions tools/scripts/tests/test-pre-push-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ make_repo() {
echo run >> "$(dirname "${BASH_SOURCE[0]}")/../../build/gate-runs"
[[ "$(readlink /proc/self/fd/0)" == /dev/null ]] && echo detached >> "$(dirname "${BASH_SOURCE[0]}")/../../build/gate-stdin"
echo "base=${MULL_DIFF_BASE:-}" >> "$(dirname "${BASH_SOURCE[0]}")/../../build/gate-env"
if [[ -n ${STUB_FOREIGN_REPO:-} ]]; then
git -C "$STUB_FOREIGN_REPO" rev-parse --absolute-git-dir > "$(dirname "${BASH_SOURCE[0]}")/../../build/gate-foreign-dir"
fi
exit "${STUB_GATE_RC:-0}"
STUB
chmod +x "$root/tools/scripts/preflight.sh" "$root/tools/scripts/git-hooks/pre-push"
Expand Down Expand Up @@ -156,6 +159,21 @@ check "a delete push exits 0 without running the gate" "$(yes_if "$rc$(runs "$ro
run_hook "$root" "" X=1 >/dev/null
check "an empty ref list still runs the gate" "$(yes_if "$(runs "$root")" 1)"

# A real linked-worktree hook receives GIT_DIR from Git. The gate's fixture
# repositories must resolve their own Git context, not the pushed worktree's.
linked="$(mktemp -d /tmp/wek-hook-linked-XXXXXX)"
foreign="$(mktemp -d /tmp/wek-hook-foreign-XXXXXX)"
TMPS+=("$linked" "$foreign")
git -C "$root" worktree add -q --detach "$linked" HEAD
git -C "$foreign" init -q
mkdir -p "$linked/build"
out="$(cd "$linked" && printf '%s' "$(refline "$sha2" "$ZERO")" |
STUB_FOREIGN_REPO="$foreign" WEK_GATE_FORCE=1 \
git -c core.hooksPath=tools/scripts/git-hooks hook run pre-push 2>&1)"; rc=$?
check "a real linked-worktree hook runs the gate once" "$(yes_if "$rc$(runs "$linked")" 01)" "$out"
check "the gate can resolve a foreign repository independently" \
"$(yes_if "$(cat "$linked/build/gate-foreign-dir" 2>/dev/null)" "$foreign/.git")" "$out"

echo
if [[ "$FAIL" -gt 0 ]]; then
printf '%s%d passed, %d failed%s\n' "$RED" "$PASS" "$FAIL" "$RESET"
Expand Down