Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions scripts/install-git-hooks
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ CURRENT_STEP=0
progress "$CURRENT_STEP" "$TOTAL_STEPS"

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

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

# 2. Check GitHub account
Expand Down Expand Up @@ -88,19 +89,16 @@ fi
((CURRENT_STEP++))
progress "$CURRENT_STEP" "$TOTAL_STEPS"

mkdir -p .git/hooks
HOOKS_DIR=".git/hooks"
mkdir -p "$HOOKS_DIR" || exit 1

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

ln -sf ../../scripts/commit-msg.hook .git/hooks/commit-msg || exit 1
chmod +x .git/hooks/commit-msg

ln -sf ../../scripts/pre-push.hook .git/hooks/pre-push || exit 1
chmod +x .git/hooks/pre-push

ln -sf ../../scripts/prepare-commit-msg.hook .git/hooks/prepare-commit-msg || exit 1
chmod +x .git/hooks/prepare-commit-msg
for hook in "${HOOKS[@]}"; do
ln -sf "../../scripts/${hook}.hook" "$HOOKS_DIR/$hook" || exit 1
chmod +x "$HOOKS_DIR/$hook"
done

touch .git/hooks/applied || exit 1

Expand Down