From 49005fbffbb7d7512af77798562db0b79c43ad27 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Mon, 24 Feb 2020 18:27:37 +0100 Subject: [PATCH] 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. --- configure-repo.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure-repo.sh b/configure-repo.sh index c560014e03..17202a1930 100755 --- a/configure-repo.sh +++ b/configure-repo.sh @@ -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 ;; *)