Skip to content

Commit

Permalink
Add check if hook exist before trying to run it
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Mar 19, 2024
1 parent 31586ac commit 75ce346
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions roles/git/files/git/hooks/post-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

git_root_dir=$(git rev-parse --show-toplevel)

if ! compgen -G "${git_root_dir}"/.git/hooks/post-checkout-* > /dev/null; then
exit 0
fi

for hook in "${git_root_dir}"/.git/hooks/post-checkout-*; do
if ! "${hook}"; then
exit 1
Expand Down
4 changes: 4 additions & 0 deletions roles/git/files/git/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

git_root_dir=$(git rev-parse --show-toplevel)

if ! compgen -G "${git_root_dir}"/.git/hooks/pre-commit-* > /dev/null; then
exit 0
fi

for hook in "${git_root_dir}"/.git/hooks/pre-commit-*; do
if ! "${hook}"; then
exit 1
Expand Down

0 comments on commit 75ce346

Please sign in to comment.