Skip to content

Commit e62d89a

Browse files
authored
[githooks/pre-push] Fail when sub-command fails (#969)
Previously, the script didn't properly detect when a backgrounded sub-command had failed, and unconditionally exited with status code 0. This commit fixes that behavior so that, if a sub-command fails, the script exits with a non-zero status code.
1 parent 52108ad commit e62d89a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

githooks/pre-push

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ echo "Running pre-push git hook: $0"
55
# `cargo fmt` is useful (and the good stuff is not delivered by stderr).
66
#
77
# Background all jobs and wait for them so they can run in parallel.
8-
./ci/check_fmt.sh &
9-
./ci/check_job_dependencies.sh >/dev/null &
10-
./ci/check_msrv.sh >/dev/null &
11-
./ci/check_readme.sh >/dev/null &
12-
./ci/check_versions.sh >/dev/null &
8+
./ci/check_fmt.sh & FMT_PID=$!
9+
./ci/check_job_dependencies.sh >/dev/null & JOB_DEPS_PID=$!
10+
./ci/check_msrv.sh >/dev/null & MSRV_PID=$!
11+
./ci/check_readme.sh >/dev/null & README_PID=$!
12+
./ci/check_versions.sh >/dev/null & VERSIONS_PID=$!
1313

14-
wait
14+
# `wait <pid>` exits with the same status code as the job it's waiting for.
15+
# Since we `set -e` above, this will have the effect of causing the entire
16+
# script to exit with a non-zero status code if any of these jobs does the same.
17+
# Note that, while `wait` (with no PID argument) waits for all backgrounded
18+
# jobs, it exits with code 0 even if one of the backgrounded jobs does not, so
19+
# we can't use it here.
20+
wait $FMT_PID
21+
wait $JOB_DEPS_PID
22+
wait $MSRV_PID
23+
wait $README_PID
24+
wait $VERSIONS_PID

0 commit comments

Comments
 (0)