@@ -415,6 +415,10 @@ GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=<boolean>, when true (which is
the default when running tests), errors out when an abbreviated option
is used.
+GIT_TEST_PIPEFAIL=<boolean>, when true, run 'set -o pipefail' to catch
+failures in commands that aren't the last in a pipe. Defaults to true on
+Bash and false otherwise.
+
Naming Tests
------------
@@ -64,6 +64,18 @@ then
export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
fi
+# Use set -o pipefail on platforms that support it
+GIT_TEST_PIPEFAIL_DEFAULT=false
+# TODO: detect more platforms that support `set -o pipefail`
+if test -n "$BASH_VERSION"
+then
+ GIT_TEST_PIPEFAIL_DEFAULT=true
+fi
+if git env--helper --type=bool --default="$GIT_TEST_PIPEFAIL_DEFAULT" --exit-code GIT_TEST_PIPEFAIL
+then
+ set -o pipefail
+fi
+
################################################################
# It appears that people try to run tests without building...
"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
The current convention is to ensure that git commands are not placed in the upstream of a pipe. If they are, they could fail in an undetectable manner since a pipe's return code is the last command in the pipe. However, many old tests are still written with git commands in the upstream of a pipe. In the spirit of catching these failures, run tests with `set -o pipefail` if the underlying shell is Bash. This way, we can catch failures of Git commands that may occur even in the middle of a pipeline. In the future, more shells that support `set -o pipefail` may have it enabled but let's start small for now. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/README | 4 ++++ t/test-lib.sh | 12 ++++++++++++ 2 files changed, 16 insertions(+)