Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
*.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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Dec 1, 2014
1 parent 3bc5180 commit b849b95
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
22 changes: 11 additions & 11 deletions git-am.sh
Expand Up @@ -810,10 +810,10 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."
continue
fi

if test -x "$GIT_DIR"/hooks/applypatch-msg
hook="$(git rev-parse --git-path hooks/applypatch-msg)"
if test -x "$hook"
then
"$GIT_DIR"/hooks/applypatch-msg "$dotest/final-commit" ||
stop_here $this
"$hook" "$dotest/final-commit" || stop_here $this
fi

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

if test -x "$GIT_DIR"/hooks/pre-applypatch
hook="$(git rev-parse --git-path hooks/pre-applypatch)"
if test -x "$hook"
then
"$GIT_DIR"/hooks/pre-applypatch || stop_here $this
"$hook" || stop_here $this
fi

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

if test -x "$GIT_DIR"/hooks/post-applypatch
then
"$GIT_DIR"/hooks/post-applypatch
fi
hook="$(git rev-parse --git-path hooks/post-applypatch)"
test -x "$hook" && "$hook"

go_next
done

if test -s "$dotest"/rewritten; then
git notes copy --for-rewrite=rebase < "$dotest"/rewritten
if test -x "$GIT_DIR"/hooks/post-rewrite; then
"$GIT_DIR"/hooks/post-rewrite rebase < "$dotest"/rewritten
hook="$(git rev-parse --git-path hooks/post-rewrite)"
if test -x "$hook"; then
"$hook" rebase < "$dotest"/rewritten
fi
fi

Expand Down
6 changes: 3 additions & 3 deletions git-rebase--interactive.sh
Expand Up @@ -642,9 +642,9 @@ do_next () {
git notes copy --for-rewrite=rebase < "$rewritten_list" ||
true # we don't care if this copying failed
} &&
if test -x "$GIT_DIR"/hooks/post-rewrite &&
test -s "$rewritten_list"; then
"$GIT_DIR"/hooks/post-rewrite rebase < "$rewritten_list"
hook="$(git rev-parse --git-path hooks/post-rewrite)"
if test -x "$hook" && test -s "$rewritten_list"; then
"$hook" rebase < "$rewritten_list"
true # we don't care if this hook failed
fi &&
warn "Successfully rebased and updated $head_name."
Expand Down
6 changes: 2 additions & 4 deletions git-rebase--merge.sh
Expand Up @@ -94,10 +94,8 @@ finish_rb_merge () {
if test -s "$state_dir"/rewritten
then
git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
if test -x "$GIT_DIR"/hooks/post-rewrite
then
"$GIT_DIR"/hooks/post-rewrite rebase <"$state_dir"/rewritten
fi
hook="$(git rev-parse --git-path hooks/post-rewrite)"
test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
fi
say All done.
}
Expand Down
4 changes: 2 additions & 2 deletions git-rebase.sh
Expand Up @@ -202,9 +202,9 @@ run_specific_rebase () {

run_pre_rebase_hook () {
if test -z "$ok_to_skip_pre_rebase" &&
test -x "$GIT_DIR/hooks/pre-rebase"
test -x "$(git rev-parse --git-path hooks/pre-rebase)"
then
"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} ||
"$(git rev-parse --git-path hooks/pre-rebase)" ${1+"$@"} ||
die "$(gettext "The pre-rebase hook refused to rebase.")"
fi
}
Expand Down
4 changes: 2 additions & 2 deletions templates/hooks--applypatch-msg.sample
Expand Up @@ -10,6 +10,6 @@
# To enable this hook, rename this file to "applypatch-msg".

. git-sh-setup
test -x "$GIT_DIR/hooks/commit-msg" &&
exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
:
4 changes: 2 additions & 2 deletions templates/hooks--pre-applypatch.sample
Expand Up @@ -9,6 +9,6 @@
# To enable this hook, rename this file to "pre-applypatch".

. git-sh-setup
test -x "$GIT_DIR/hooks/pre-commit" &&
exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
precommit="$(git rev-parse --git-path hooks/pre-commit)"
test -x "$precommit" && exec "$precommit" ${1+"$@"}
:

0 comments on commit b849b95

Please sign in to comment.