Skip to content

Commit c61139a

Browse files
authored
Merge pull request #224 from sysprog21/improve-install-hooks
Refine error messages of hook installer
2 parents e151924 + 05d00a2 commit c61139a

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

scripts/install-git-hooks

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ CURRENT_STEP=0
1818
progress "$CURRENT_STEP" "$TOTAL_STEPS"
1919

2020
if ! test -d .git; then
21-
throw "Execute scripts/install-git-hooks in the top-level directory."
21+
throw "Ensure the git repository is cloned correctly."
2222
fi
2323

2424
workspace=$(git rev-parse --show-toplevel)
2525
if [ ! -d "$workspace" ]; then
26-
throw "The workspace path '$workspace' contains non-ASCII characters."
26+
throw "Unable to determine the repository's top-level directory.\n\
27+
This directory $workspace does not appear to be a valid Git repository."
2728
fi
2829

2930
# 2. Check GitHub account
@@ -88,19 +89,16 @@ fi
8889
((CURRENT_STEP++))
8990
progress "$CURRENT_STEP" "$TOTAL_STEPS"
9091

91-
mkdir -p .git/hooks
92+
HOOKS_DIR=".git/hooks"
93+
mkdir -p "$HOOKS_DIR" || exit 1
9294

93-
ln -sf ../../scripts/pre-commit.hook .git/hooks/pre-commit || exit 1
94-
chmod +x .git/hooks/pre-commit
95+
# List of hook names.
96+
HOOKS=(pre-commit commit-msg pre-push prepare-commit-msg)
9597

96-
ln -sf ../../scripts/commit-msg.hook .git/hooks/commit-msg || exit 1
97-
chmod +x .git/hooks/commit-msg
98-
99-
ln -sf ../../scripts/pre-push.hook .git/hooks/pre-push || exit 1
100-
chmod +x .git/hooks/pre-push
101-
102-
ln -sf ../../scripts/prepare-commit-msg.hook .git/hooks/prepare-commit-msg || exit 1
103-
chmod +x .git/hooks/prepare-commit-msg
98+
for hook in "${HOOKS[@]}"; do
99+
ln -sf "../../scripts/${hook}.hook" "$HOOKS_DIR/$hook" || exit 1
100+
chmod +x "$HOOKS_DIR/$hook"
101+
done
104102

105103
touch .git/hooks/applied || exit 1
106104

0 commit comments

Comments
 (0)