*.sh: avoid hardcoding $GIT_DIR/hooks/...
If $GIT_COMMON_DIR is set, it should be $GIT_COMMON_DIR/hooks/, not $GIT_DIR/hooks/. Just let rev-parse --git-path handle it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 30, 2014 at 15:24 UTC
b849b954d22ee069b0edec1a12c78782ae1e629d
6 files changed
+22
-24
git-am.sh
+11
-11
@@ -810,10 +810,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
810
continue
811
fi
812
813
- if test -x "$GIT_DIR"/hooks/applypatch-msg
813
+ hook="$(git rev-parse --git-path hooks/applypatch-msg)"
814
+ if test -x "$hook"
815
then
815
- "$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" ||
816
- stop_here $this
816
+ "$hook" "$dotest/final-commit" || stop_here $this
817
fi
818
819
if test -f "$dotest/final-commit"
@@ -887,9 +887,10 @@ did you forget to use 'git add'?"
887
stop_here_user_resolve $this
888
fi
889
890
- if test -x "$GIT_DIR"/hooks/pre-applypatch
890
+ hook="$(git rev-parse --git-path hooks/pre-applypatch)"
891
+ if test -x "$hook"
892
then
892
- "$GIT_DIR"/hooks/pre-applypatch || stop_here $this
893
+ "$hook" || stop_here $this
894
fi
895
896
tree=$(git write-tree) &&
@@ -916,18 +917,17 @@ did you forget to use 'git add'?"
917
echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten"
918
fi
919
919
- if test -x "$GIT_DIR"/hooks/post-applypatch
920
- then
921
- "$GIT_DIR"/hooks/post-applypatch
922
- fi
920
+ hook="$(git rev-parse --git-path hooks/post-applypatch)"
921
+ test -x "$hook" && "$hook"
922
923
go_next
924
done
925
926
if test -s "$dotest"/rewritten; then
927
git notes copy --for-rewrite=rebase < "$dotest"/rewritten
929
- if test -x "$GIT_DIR"/hooks/post-rewrite; then
930
- "$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
928
+ hook="$(git rev-parse --git-path hooks/post-rewrite)"
929
+ if test -x "$hook"; then
930
+ "$hook" rebase < "$dotest"/rewritten
931
fi
932
fi
933
git-rebase--interactive.sh
+3
-3
@@ -642,9 +642,9 @@ do_next () {
642
git notes copy --for-rewrite=rebase < "$rewritten_list" ||
643
true # we don't care if this copying failed
644
} &&
645
- if test -x "$GIT_DIR"/hooks/post-rewrite &&
646
- test -s "$rewritten_list"; then
647
- "$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
645
+ hook="$(git rev-parse --git-path hooks/post-rewrite)"
646
+ if test -x "$hook" && test -s "$rewritten_list"; then
647
+ "$hook" rebase < "$rewritten_list"
648
true # we don't care if this hook failed
649
fi &&
650
warn "Successfully rebased and updated $head_name."
git-rebase--merge.sh
+2
-4
@@ -94,10 +94,8 @@ finish_rb_merge () {
94
if test -s "$state_dir"/rewritten
95
then
96
git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
97
- if test -x "$GIT_DIR"/hooks/post-rewrite
98
- then
99
- "$GIT_DIR"/hooks/post-rewrite rebase <"$state_dir"/rewritten
100
- fi
97
+ hook="$(git rev-parse --git-path hooks/post-rewrite)"
98
+ test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
99
fi
100
say All done.
101
}
git-rebase.sh
+2
-2
@@ -202,9 +202,9 @@ run_specific_rebase () {
202
203
run_pre_rebase_hook () {
204
if test -z "$ok_to_skip_pre_rebase" &&
205
- test -x "$GIT_DIR/hooks/pre-rebase"
205
+ test -x "$(git rev-parse --git-path hooks/pre-rebase)"
206
then
207
- "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
207
+ "$(git rev-parse --git-path hooks/pre-rebase)" ${1+"$@"} ||
208
die "$(gettext "The pre-rebase hook refused to rebase.")"
209
fi
210
}
templates/hooks--applypatch-msg.sample
+2
-2
@@ -10,6 +10,6 @@
10
# To enable this hook, rename this file to "applypatch-msg".
11
12
. git-sh-setup
13
-test -x "$GIT_DIR/hooks/commit-msg" &&
14
- exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
13
+commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
14
+test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
15
:
templates/hooks--pre-applypatch.sample
+2
-2
@@ -9,6 +9,6 @@
9
# To enable this hook, rename this file to "pre-applypatch".
10
11
. git-sh-setup
12
-test -x "$GIT_DIR/hooks/pre-commit" &&
13
- exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
12
+precommit="$(git rev-parse --git-path hooks/pre-commit)"
13
+test -x "$precommit" && exec "$precommit" ${1+"$@"}
14
: