diff --git a/check_repos.sh b/check_repos.sh index f09d67e..d0e7678 100755 --- a/check_repos.sh +++ b/check_repos.sh @@ -42,8 +42,8 @@ check_hooks_gitleaks() { check_hooks_path() { # ensure that repos are not overriding the hookspath - hooks_path_origin=$(cd "$gitrepo"; git config --show-origin core.hooksPath) - if [[ "$hooks_path_origin" =~ /^file:$HOME/.gitconfig.*$HOME/.git-support/hooks ]]; then + hooks_path_origin=$(cd "$gitrepo"; git config --show-origin core.hooksPath | awk '{print $2}') + if [[ "$hooks_path_origin" != "${HOME}/.git-support/hooks" ]]; then return 1 fi return 0 diff --git a/development.bats b/development.bats index a7dcffd..16c7579 100644 --- a/development.bats +++ b/development.bats @@ -25,6 +25,11 @@ testCommit() { assert_failure } +@test "check_repo fails when core.hooksPath is overridden" { + run changeGitHooksPath + assert_failure +} + @test "check_repo fails when you have a personal email" { git config --file $REPO_PATH/.git/config user.email foo@bar.com run ./check_repos.sh $REPO_PATH check_user_email >&3 diff --git a/test_helper.bash b/test_helper.bash index 2c1d75b..ce30100 100644 --- a/test_helper.bash +++ b/test_helper.bash @@ -131,6 +131,11 @@ turnOffHooksGitleaks() { ./check_repos.sh $REPO_PATH check_hooks_gitleaks } +changeGitHooksPath() { + (cd $REPO_PATH && git config --local core.hooksPath "foobar") + ./check_repos.sh $REPO_PATH check_hooks_path +} + createPrecommitNoGitleaks() { (cd $REPO_PATH && mv .git/hooks/pre-commit.sample .git/hooks/pre-commit) }