-
Notifications
You must be signed in to change notification settings - Fork 5
Closed
Description
Problem
The pre-commit hook runner in git/hooks/pre-commit fails when no *.pre-commit scripts exist in ~/.dotfiles/git/hooks/.
The glob $hooks/*.$hook_type doesn't expand when there are no matching files, so the shell tries to execute the literal string ~/.dotfiles/git/hooks/*.pre-commit as a command, which fails:
Executing pre-commit hook(s)
.git/hooks/pre-commit: line 14: /Users/defilan/.dotfiles/git/hooks/*.pre-commit: No such file or directory
Commit Failed.
This blocks all commits unless --no-verify is used.
Root Cause
for hook in $hooks/*.$hook_type; do
echo ""
echo "${COLOR_LIGHTPURPLE}Executing ${hook}${COLOR_NONE}"
${hook}
EXIT_CODE=$((${EXIT_CODE} + $?))
doneWhen the glob has no matches, bash iterates once with the literal unexpanded glob string.
Fix
Add a guard before executing:
for hook in $hooks/*.$hook_type; do
[ -f "$hook" ] || continue
echo ""
echo "${COLOR_LIGHTPURPLE}Executing ${hook}${COLOR_NONE}"
${hook}
EXIT_CODE=$((${EXIT_CODE} + $?))
doneOr use nullglob at the top of the script.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels