git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] respect core.hooksPath, falling back to .git/hooks

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 14, 2017, 13:24 UTC
Message-ID
<alpine.DEB.2.21.1.1706141516540.171564@virtualbox>
In-Reply-To
<20170602202301.6413-1-philipp@gortan.org>
Hi Philipp,
On Fri, 2 Jun 2017, Philipp Gortan wrote:
> Signed-off-by: Philipp Gortan <philipp@gortan.org>

I just saw this. I made sure that the thread to which I just replied did not have any news from you, but you simply started a new thread ;-)

This commit message needs a little bit of love. Something along the lines:
	Since v2.9.0, Git knows about the config variable core.hookspath
	that allows overriding the path to the directory containing the
	Git hooks.
	Since v2.10.0, the `--git-path` option respects that config
	variable, too, so we may just as well use that command.
	For Git versions older than v2.5.0 (which was the first version to
	support the `--git-path` option for the `rev-parse` command), we
	simply fall back to the previous code.

(This assumes that you'll go with the approach I outlined in the other thread, comparing the Git version to 2.5.0 and going with --git-path if available.)

> ---
> 
> The following patch tries to fix git-gui to respect the core.hooksPath config
> variable, falling back to the old behavior.

That would also have been a decent commit message, if a bit short. But you need to put this text before the `---` line, even before the `Signed-off-by:` footer.

Show 10 quoted lines
> diff --git a/git-gui.sh b/git-gui.sh
> index 5bc21b8..a5335b1 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -624,7 +624,10 @@ proc git_write {args} {
>  }
>  
>  proc githook_read {hook_name args} {
> -	set pchook [gitdir hooks $hook_name]
> +	if {[catch {set hooksdir [git config core.hooksPath]}]} {

Did you not mean [get_config core.hookspath] here, i.e. get_config and the key all lower-case?

Show 5 quoted lines
> +		set hooksdir [gitdir hooks]
> +	}
> +	set pchook [file join $hooksdir $hook_name]
>  	lappend args 2>@1
>  

The problem I see with that is, as I mentioned in the other thread, that it duplicates the logic in config.c that may change at any stage.

Even worse: it is inconsistent with the way Git handles core.hooksPath, if the installed `git` executable predates v2.9.0. Git GUI explicitly allows for being used with a large range of Git versions.

In short: I think it would be better to go with the approach I outlined in the other thread. I'll reproduce the patch (completely untested) here:

-- snipsnap --
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 37c1c5d227b..3067a3b000a 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -624,7 +624,11 @@ proc git_write {args} {
 }
 
 proc githook_read {hook_name args} {
-	set pchook [gitdir hooks $hook_name]
+	if {[package vcompare $::_git_version 2.5.0] >= 0} {
+		set pchook [git rev-parse --git-path "hooks/$hook_name"]
+	} else {
+		set pchook [gitdir hooks $hook_name]
+	}
 	lappend args 2>@1
 
 	# On Windows [file executable] might lie so we need to ask
Previous: Philipp GortanNext: Philip Oakley
Message 6 of 20 in “git-gui ignores core.hooksPath”
  1. Philipp GortanJun 2, 2017
  2. Samuel LijinJun 2, 2017
  3. Ævar Arnfjörð BjarmasonJun 2, 2017
  4. respect core.hooksPath, falling back to .git/hooksPhilipp Gortan, Jun 2, 2017
  5. Philipp GortanJun 2, 2017
  6. Johannes SchindelinJun 14, 2017
  7. Philip OakleyJun 2, 2017
  8. Philipp GortanJun 2, 2017
  9. Johannes SchindelinJun 14, 2017
  10. Philipp GortanJun 14, 2017
  11. Chris MaesApr 10, 2018
  12. Johannes SchindelinApr 10, 2018
  13. Junio C HamanoApr 10, 2018
  14. Ævar Arnfjörð BjarmasonApr 10, 2018
  15. Junio C HamanoApr 11, 2018
  16. Bert WesargJun 5, 2018
  17. Stefan BellerJun 11, 2018
  18. Johannes SixtJun 12, 2018
  19. Johannes SchindelinJul 10, 2018
  20. Philip OakleyJul 10, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.