Skip to content

Commit

Permalink
git-gui - use git-hook, honor core.hooksPath
Browse files Browse the repository at this point in the history
git-gui currently runs some hooks directly using its own code written
before 2010, long predating git v2.9 that added the core.hooksPath
configuration to override the assumed location at $GIT_DIR/hooks.  Thus,
git-gui looks for and runs hooks including prepare-commit-msg,
commit-msg, pre-commit, post-commit, and post-checkout from
$GIT_DIR/hooks, regardless of configuration. Commands (e.g., git-merge)
that git-gui invokes directly do honor core.hooksPath, meaning the
overall behaviour is inconsistent.

Furthermore, since v2.36 git exposes its hook execution machinery via
`git-hook run`, eliminating the need for others to maintain code
duplicating that functionality.  Using git-hook will both fix git-gui's
current issues on hook configuration and (presumably) reduce the
maintenance burden going forward. So, teach git-gui to use git-hook.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
mark987 authored and gitster committed Sep 18, 2023
1 parent 3f71c97 commit 0730a5a
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions git-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -661,31 +661,8 @@ proc git_write {args} {
}

proc githook_read {hook_name args} {
set pchook [gitdir hooks $hook_name]
lappend args 2>@1

# On Windows [file executable] might lie so we need to ask
# the shell if the hook is executable. Yes that's annoying.
#
if {[is_Windows]} {
upvar #0 _sh interp
if {![info exists interp]} {
set interp [_which sh]
}
if {$interp eq {}} {
error "hook execution requires sh (not in PATH)"
}

set scr {if test -x "$1";then exec "$@";fi}
set sh_c [list $interp -c $scr $interp $pchook]
return [_open_stdout_stderr [concat $sh_c $args]]
}

if {[file executable $pchook]} {
return [_open_stdout_stderr [concat [list $pchook] $args]]
}

return {}
set cmd [concat git hook run --ignore-missing $hook_name -- $args 2>@1]
return [_open_stdout_stderr $cmd]
}

proc kill_file_process {fd} {
Expand Down

0 comments on commit 0730a5a

Please sign in to comment.