Skip to content

Commit b849b95

Browse files
pcloudsgitster
authored andcommitted
*.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>
1 parent 3bc5180 commit b849b95

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

git-am.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
810810
continue
811811
fi
812812

813-
if test -x "$GIT_DIR"/hooks/applypatch-msg
813+
hook="$(git rev-parse --git-path hooks/applypatch-msg)"
814+
if test -x "$hook"
814815
then
815-
"$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" ||
816-
stop_here $this
816+
"$hook" "$dotest/final-commit" || stop_here $this
817817
fi
818818

819819
if test -f "$dotest/final-commit"
@@ -887,9 +887,10 @@ did you forget to use 'git add'?"
887887
stop_here_user_resolve $this
888888
fi
889889

890-
if test -x "$GIT_DIR"/hooks/pre-applypatch
890+
hook="$(git rev-parse --git-path hooks/pre-applypatch)"
891+
if test -x "$hook"
891892
then
892-
"$GIT_DIR"/hooks/pre-applypatch || stop_here $this
893+
"$hook" || stop_here $this
893894
fi
894895

895896
tree=$(git write-tree) &&
@@ -916,18 +917,17 @@ did you forget to use 'git add'?"
916917
echo "$(cat "$dotest/original-commit") $commit" >> "$dotest/rewritten"
917918
fi
918919

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"
923922

924923
go_next
925924
done
926925

927926
if test -s "$dotest"/rewritten; then
928927
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
931931
fi
932932
fi
933933

git-rebase--interactive.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,9 @@ do_next () {
642642
git notes copy --for-rewrite=rebase < "$rewritten_list" ||
643643
true # we don't care if this copying failed
644644
} &&
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"
648648
true # we don't care if this hook failed
649649
fi &&
650650
warn "Successfully rebased and updated $head_name."

git-rebase--merge.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ finish_rb_merge () {
9494
if test -s "$state_dir"/rewritten
9595
then
9696
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
10199
fi
102100
say All done.
103101
}

git-rebase.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ run_specific_rebase () {
202202

203203
run_pre_rebase_hook () {
204204
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)"
206206
then
207-
"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
207+
"$(git rev-parse --git-path hooks/pre-rebase)" ${1+"$@"} ||
208208
die "$(gettext "The pre-rebase hook refused to rebase.")"
209209
fi
210210
}

templates/hooks--applypatch-msg.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
# To enable this hook, rename this file to "applypatch-msg".
1111

1212
. 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+"$@"}
1515
:

templates/hooks--pre-applypatch.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
# To enable this hook, rename this file to "pre-applypatch".
1010

1111
. 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+"$@"}
1414
:

0 commit comments

Comments
 (0)