Skip to content

Commit

Permalink
Reset original global git config after tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kiemes and ansd committed Mar 15, 2019
1 parent fa47338 commit 5134444
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ setup() {
unset GIT_DUET_ROTATE_AUTHOR
unset GIT_DUET_SET_GIT_USER_CONFIG
unset GIT_DUET_CO_AUTHORED_BY
export TEMPLATE_DIR_BAK=$(git config --global init.templateDir)
export HOOKS_PATH_BAK=$(git config --global core.hooksPath)
git config --global --unset init.templateDir || true
git config --global --unset core.hooksPath || true

Expand Down Expand Up @@ -55,6 +57,16 @@ EOF
teardown() {
git config --global --remove-section $GIT_DUET_CONFIG_NAMESPACE || true
git config --global --unset init.templateDir || true

#Reset original git global config. Otherwise tests would potentially change the system config.
if [[ -n "$HOOKS_PATH_BAK" ]]; then
git config --global core.hooksPath "$HOOKS_PATH_BAK"
fi

if [[ -n "$TEMPLATE_DIR_BAK" ]]; then
git config --global init.templateDir "$TEMPLATE_DIR_BAK"
fi

rm -rf "$GIT_DUET_TEST_DIR"
}

Expand Down

0 comments on commit 5134444

Please sign in to comment.