Skip to content

Commit

Permalink
Fix check for overridden hooks path (#91)
Browse files Browse the repository at this point in the history
* fix logic for checking whether repo is overriding core.hooksPath

* add development test to ensure check for core.hooksPath being overridden works correctly
  • Loading branch information
markdboyd authored Aug 26, 2024
1 parent a303ab6 commit b584c81
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions check_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions development.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
run ./check_repos.sh $REPO_PATH check_user_email >&3
Expand Down
5 changes: 5 additions & 0 deletions test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b584c81

Please sign in to comment.