# [PATCH] make rebase respect core.hooksPath if set

6 messages from 2016-08-14 to 2016-08-16. Participants: ryenus, Mike Rappazzo, Johannes Schindelin, Jeff King.
Thread: https://gitlist.dev/t/43841

## ryenus, 2016-08-14 15:58

Subject: [PATCH] make rebase respect core.hooksPath if set
Message-ID: <CAKkAvaxWk6SK4EYPaWXHQoVBh9qLgHoEqAh9+dgOrjncsi5QyA@mail.gmail.com>
URL: https://gitlist.dev/e/CAKkAvaxWk6SK4EYPaWXHQoVBh9qLgHoEqAh9%2BdgOrjncsi5QyA%40mail.gmail.com

```
when looking for pre-rebase and post-rewrite hooks, git-rebase
only looks for hooks dir using `git rev-parse --git-path hooks`,
which didn't consider the path overridden by core.hooksPath.

Signed-off-by: ryenus <ryenus@gmail.com>
---
 git-rebase--interactive.sh | 14 +++++++++-----
 git-rebase--merge.sh       |  4 +++-
 git-rebase.sh              |  7 +++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index e2da524..e8af70d 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -724,11 +724,15 @@ Commit or stash your changes, and then run
  git notes copy --for-rewrite=rebase < "$rewritten_list" ||
  true # we don't care if this copying failed
  } &&
- 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 &&
+ {
+ hooks_path=$(git config --get core.hooksPath)
+ hooks_path="${hooks_path:-$(git rev-parse --git-path hooks)}"
+ hook="${hooks_path}/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 "$(eval_gettext "Successfully rebased and updated \$head_name.")"

  return 1 # not failure; just to break the do_rest loop
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
index 06a4723..df5073e 100644
--- a/git-rebase--merge.sh
+++ b/git-rebase--merge.sh
@@ -96,7 +96,9 @@ finish_rb_merge () {
  if test -s "$state_dir"/rewritten
  then
  git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
- hook="$(git rev-parse --git-path hooks/post-rewrite)"
+ hooks_path=$(git config --get core.hooksPath)
+ hooks_path="${hooks_path:-$(git rev-parse --git-path hooks)}"
+ hook="${hooks_path}/post-rewrite"
  test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
  fi
  say All done.
diff --git a/git-rebase.sh b/git-rebase.sh
index 04f6e44..c9ba747 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -203,10 +203,13 @@ run_specific_rebase () {
 }

 run_pre_rebase_hook () {
+ hooks_path=$(git config --get core.hooksPath)
+ hooks_path="${hooks_path:-$(git rev-parse --git-path hooks)}"
+ hook="${hooks_path}/pre-rebase"
  if test -z "$ok_to_skip_pre_rebase" &&
-   test -x "$(git rev-parse --git-path hooks/pre-rebase)"
+   test -x "$hook"
  then
- "$(git rev-parse --git-path hooks/pre-rebase)" ${1+"$@"} ||
+ "$hook" ${1+"$@"} ||
  die "$(gettext "The pre-rebase hook refused to rebase.")"
  fi
 }
-- 
2.9.3

```

## ryenus, 2016-08-14 16:29

Subject: Re: [PATCH] make rebase respect core.hooksPath if set
Message-ID: <CAKkAvazV8umqbs+rTEG2399Ox0pGL1YAXsgLqHusb15RhzyH7Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAKkAvazV8umqbs%2BrTEG2399Ox0pGL1YAXsgLqHusb15RhzyH7Q%40mail.gmail.com
In-Reply-To: <CAKkAvaxWk6SK4EYPaWXHQoVBh9qLgHoEqAh9+dgOrjncsi5QyA@mail.gmail.com>

```
Patch attached.

It seems gmail ruined the white spaces.
Not sure how to stop gmail from doing that.
Sorry for me, and for Gmail.


From 67418dd8ffad7c07ed95437f7a4d1359da9d93d2 Mon Sep 17 00:00:00 2001
From: ryenus <ryenus@gmail.com>
Date: Sun, 14 Aug 2016 19:16:27 +0800
Subject: [PATCH] make rebase respect core.hooksPath if set

when looking for pre-rebase and post-rewrite hooks, git-rebase
only looks for hooks dir using `git rev-parse --git-path hooks`,
which didn't consider the path overridden by core.hooksPath.

Signed-off-by: ryenus <ryenus@gmail.com>
---
 git-rebase--interactive.sh | 14 +++++++++-----
 git-rebase--merge.sh       |  4 +++-
 git-rebase.sh              |  7 +++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index e2da524..e8af70d 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -724,11 +724,15 @@ Commit or stash your changes, and then run
 		git notes copy --for-rewrite=rebase < "$rewritten_list" ||
 		true # we don't care if this copying failed
 	} &&
-	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 &&
+	{
+		hooks_path=$(git config --get core.hooksPath)
+		hooks_path="${hooks_path:-$(git rev-parse --git-path hooks)}"
+		hook="${hooks_path}/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 "$(eval_gettext "Successfully rebased and updated \$head_name.")"
 
 	return 1 # not failure; just to break the do_rest loop
diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh
index 06a4723..df5073e 100644
--- a/git-rebase--merge.sh
+++ b/git-rebase--merge.sh
@@ -96,7 +96,9 @@ finish_rb_merge () {
 	if test -s "$state_dir"/rewritten
 	then
 		git notes copy --for-rewrite=rebase <"$state_dir"/rewritten
-		hook="$(git rev-parse --git-path hooks/post-rewrite)"
+		hooks_path=$(git config --get core.hooksPath)
+		hooks_path="${hooks_path:-$(git rev-parse --git-path hooks)}"
+		hook="${hooks_path}/post-rewrite"
 		test -x "$hook" && "$hook" rebase <"$state_dir"/rewritten
 	fi
 	say All done.
diff --git a/git-rebase.sh b/git-rebase.sh
index 04f6e44..c9ba747 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -203,10 +203,13 @@ run_specific_rebase () {
 }
 
 run_pre_rebase_hook () {
+	hooks_path=$(git config --get core.hooksPath)
+	hooks_path="${hooks_path:-$(git rev-parse --git-path hooks)}"
+	hook="${hooks_path}/pre-rebase"
 	if test -z "$ok_to_skip_pre_rebase" &&
-	   test -x "$(git rev-parse --git-path hooks/pre-rebase)"
+	   test -x "$hook"
 	then
-		"$(git rev-parse --git-path hooks/pre-rebase)" ${1+"$@"} ||
+		"$hook" ${1+"$@"} ||
 		die "$(gettext "The pre-rebase hook refused to rebase.")"
 	fi
 }
-- 
2.9.3


```

## Mike Rappazzo, 2016-08-14 20:03

Subject: Re: [PATCH] make rebase respect core.hooksPath if set
Message-ID: <CANoM8SWutGQaHJa6VCSJbRrFc9Dap0pKNUj74hhjm6hyHtYXtg@mail.gmail.com>
URL: https://gitlist.dev/e/CANoM8SWutGQaHJa6VCSJbRrFc9Dap0pKNUj74hhjm6hyHtYXtg%40mail.gmail.com
In-Reply-To: <CAKkAvazV8umqbs+rTEG2399Ox0pGL1YAXsgLqHusb15RhzyH7Q@mail.gmail.com>

```
On Sun, Aug 14, 2016 at 12:29 PM, ryenus <ryenus@gmail.com> wrote:
> Patch attached.
>
> It seems gmail ruined the white spaces.
> Not sure how to stop gmail from doing that.
> Sorry for me, and for Gmail.

Did you use git-send-email?  I don't think that the gmail ui works.
If you have 2-factor authentication, there are instructions on how to
set that up in the docs in Documentation/git-format-patch.txt

```

## Johannes Schindelin, 2016-08-15 12:24

Subject: Re: [PATCH] make rebase respect core.hooksPath if set
Message-ID: <alpine.DEB.2.20.1608151422210.4924@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1608151422210.4924%40virtualbox
In-Reply-To: <CAKkAvaxWk6SK4EYPaWXHQoVBh9qLgHoEqAh9+dgOrjncsi5QyA@mail.gmail.com>

```
Hi ryenus,

On Sun, 14 Aug 2016, ryenus wrote:

> when looking for pre-rebase and post-rewrite hooks, git-rebase
> only looks for hooks dir using `git rev-parse --git-path hooks`,
> which didn't consider the path overridden by core.hooksPath.

Would it not be more appropriate to teach --git-path hooks to respect the
core.hooksPath variable? This would be in line with --git-path objects
respecting the GIT_OBJECT_DIRECTORY environment variable.

> Signed-off-by: ryenus <ryenus@gmail.com>

From
https://github.com/git/git/blob/v2.9.3/Documentation/SubmittingPatches#L290-L291

> Also notice that a real name is used in the Signed-off-by: line. Please
> don't hide your real name.

Thanks,
Johannes

```

## Jeff King, 2016-08-15 12:31

Subject: Re: [PATCH] make rebase respect core.hooksPath if set
Message-ID: <20160815123150.nmgch55wzzcv5oue@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20160815123150.nmgch55wzzcv5oue%40sigill.intra.peff.net
In-Reply-To: <alpine.DEB.2.20.1608151422210.4924@virtualbox>

```
On Mon, Aug 15, 2016 at 02:24:59PM +0200, Johannes Schindelin wrote:

> > when looking for pre-rebase and post-rewrite hooks, git-rebase
> > only looks for hooks dir using `git rev-parse --git-path hooks`,
> > which didn't consider the path overridden by core.hooksPath.
> 
> Would it not be more appropriate to teach --git-path hooks to respect the
> core.hooksPath variable? This would be in line with --git-path objects
> respecting the GIT_OBJECT_DIRECTORY environment variable.

Good idea. I think that logic is all in path.c:adjust_git_path().

And then I suspect the manual handling of git_hooks_path in find_hook()
could go away (because strbuf_git_path would just do the right thing
automatically).

-Peff

```

## ryenus, 2016-08-16 02:01

Subject: Re: [PATCH] make rebase respect core.hooksPath if set
Message-ID: <CAKkAvaxEeOvCy-8EZ=BeWVUPCLec_dFNv+dNpj9_VsECzAT2YA@mail.gmail.com>
URL: https://gitlist.dev/e/CAKkAvaxEeOvCy-8EZ%3DBeWVUPCLec_dFNv%2BdNpj9_VsECzAT2YA%40mail.gmail.com
In-Reply-To: <alpine.DEB.2.20.1608151422210.4924@virtualbox>

```
On 15 August 2016 at 20:24, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:

> Would it not be more appropriate to teach --git-path hooks to respect the
> core.hooksPath variable? This would be in line with --git-path objects
> respecting the GIT_OBJECT_DIRECTORY environment variable.

Indeed, I've thought about that, too, due to the bad smell of duplication,
but not sure if that's the right position among all the abstraction layers.

Also it's more convenient to come up with a shell based fix on local
installation.

Thanks

```
