feat(common): Support git worktree when configuring local hooks

When using worktrees in git the hooks directory is under the main
worktree directory. `$ROOT/.git` might be a text file instead of a
folder. `git rev-parse` will return the correct location in all
cases.
This commit is contained in:
Eberhard Beilharz 2020-02-24 18:27:37 +01:00
parent c850fc21df
commit 49005fbffb
No known key found for this signature in database
GPG key ID: 64A39A9E98B53105

View file

@ -6,7 +6,6 @@
# Run this script once to configure your system to work with our Git workflow.
#
ROOT=$(git rev-parse --show-toplevel)
if [[ -n "$WINDIR" ]]; then
# https://stackoverflow.com/a/39160850/1836776
SCRIPT_DIR=$(cmd //C cd)
@ -32,8 +31,9 @@ case $1 in
cmd //C "mklink $WinPWD\\.git\\hooks\\commit-msg $WinPWD\\resources\\git-hooks\\commit-msg"
cmd //C "mklink $WinPWD\\.git\\hooks\\prepare-commit-msg $WinPWD\\resources\\git-hooks\\prepare-commit-msg"
else
ln -sf "$SCRIPT_DIR/resources/git-hooks/commit-msg" "$ROOT/.git/hooks/commit-msg"
ln -sf "$SCRIPT_DIR/resources/git-hooks/prepare-commit-msg" "$ROOT/.git/hooks/prepare-commit-msg"
HOOKSDIR=$(git rev-parse --git-path hooks)
ln -sf "$SCRIPT_DIR/resources/git-hooks/commit-msg" "$HOOKSDIR/commit-msg"
ln -sf "$SCRIPT_DIR/resources/git-hooks/prepare-commit-msg" "$HOOKSDIR/prepare-commit-msg"
fi
;;
*)