Use full paths when installing hooks, safer strings

This commit is contained in:
Daniel Martí 2014-05-28 09:21:37 +02:00
parent b62aa59355
commit eb3d82e31a

View file

@ -2,28 +2,29 @@
# #
# Install all the client hooks # Install all the client hooks
BASE_DIR=$(dirname $0) BASE_DIR="$(cd $(dirname $0); pwd -P)"
HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc" HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc"
HOOK_DIR=$(git rev-parse --show-toplevel)/.git/hooks HOOK_DIR="$(git rev-parse --show-toplevel)/.git/hooks"
for hook in $HOOK_NAMES; do for hook in $HOOK_NAMES; do
shipped_hook=$BASE_DIR/$hook shipped_hook="$BASE_DIR/$hook"
installed_hook=$HOOK_DIR/$hook installed_hook="$HOOK_DIR/$hook"
# If we don't distribute it, continue # If we don't distribute it, continue
if [ ! -f $shipped_hook ]; then if [ ! -f "$shipped_hook" ]; then
continue continue
fi fi
# If the hook already exists, continue if [ -h "$installed_hook" ]; then
if [ -e $installed_hook -o -h $installed_hook ]; then echo "$installed_hook is a symlink - replacing."
elif [ -e "$installed_hook" ]; then
echo "$installed_hook hook already exists." echo "$installed_hook hook already exists."
continue continue
fi fi
# Create the symlink # Create the symlink
echo "ln -s $shipped_hook $installed_hook" echo "ln -s -f \"$shipped_hook\" \"$installed_hook\""
ln -s $shipped_hook $installed_hook ln -s -f "$shipped_hook" "$installed_hook"
done done