Skip to content

Commit 5134444

Browse files
Kiemesansd
andcommitted
Reset original global git config after tests
If a contributor running the bats tests locally had a global git config for `init.templateDir` or `core.hooksPath`, the values would be cleared by the tests. Co-authored-by: David Ansari <david.ansari@sap.com>
1 parent fa47338 commit 5134444

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/test_helper.bash

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ setup() {
77
unset GIT_DUET_ROTATE_AUTHOR
88
unset GIT_DUET_SET_GIT_USER_CONFIG
99
unset GIT_DUET_CO_AUTHORED_BY
10+
export TEMPLATE_DIR_BAK=$(git config --global init.templateDir)
11+
export HOOKS_PATH_BAK=$(git config --global core.hooksPath)
1012
git config --global --unset init.templateDir || true
1113
git config --global --unset core.hooksPath || true
1214

@@ -55,6 +57,16 @@ EOF
5557
teardown() {
5658
git config --global --remove-section $GIT_DUET_CONFIG_NAMESPACE || true
5759
git config --global --unset init.templateDir || true
60+
61+
#Reset original git global config. Otherwise tests would potentially change the system config.
62+
if [[ -n "$HOOKS_PATH_BAK" ]]; then
63+
git config --global core.hooksPath "$HOOKS_PATH_BAK"
64+
fi
65+
66+
if [[ -n "$TEMPLATE_DIR_BAK" ]]; then
67+
git config --global init.templateDir "$TEMPLATE_DIR_BAK"
68+
fi
69+
5870
rm -rf "$GIT_DUET_TEST_DIR"
5971
}
6072

0 commit comments

Comments
 (0)