From 3d45f01728497c2ac88d740b65837c1a823d950a Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sun, 5 Apr 2020 13:17:10 +0200 Subject: [PATCH] test/test_helper: Don't use system/user `git` config Git uses system-wide and user-wide configurations per default and these can interfere with our tests. Keep `git` from using them by setting the according environment variables. This might also help with other tools which access user's home directory. --- test/test_helper.bash | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test_helper.bash b/test/test_helper.bash index 9784cdf8..cd75f05a 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -17,6 +17,23 @@ fi export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/.." export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/../test_lib}" +# be independent of git's system configuration +export GIT_CONFIG_NOSYSTEM + +# Some tools, e.g. `git` use configuration files from the $HOME directory, +# which interferes with our tests. The only way to keep `git` from doing this +# seems to set HOME explicitly to a separate location. +# Refer to https://git-scm.com/docs/git-config#FILES. +unset XDG_CONFIG_HOME +export HOME="${BATS_TMPDIR}/home" +mkdir -p "${HOME}" + +# For `git` tests to run well, user name and email need to be set. +# Refer to https://git-scm.com/docs/git-commit#_commit_information. +# This goes to the test-specific config, due to the $HOME overridden above. +git config --global user.name "John Doe" +git config --global user.email "johndoe@example.com" + load "${TEST_DEPS_DIR}/bats-support/load.bash" load "${TEST_DEPS_DIR}/bats-assert/load.bash" load "${TEST_DEPS_DIR}/bats-file/load.bash"