From: Mark Levedahl <mlevedahl@gmail.com>
To: gitster@pobox.com, johannes.schindelin@gmx.de,
me@yadavpratyush.com, git@vger.kernel.org
Cc: Mark Levedahl <mlevedahl@gmail.com>
Subject: [PATCH v2] git-gui - re-enable use of hook scripts
Date: Sat, 16 Sep 2023 17:01:31 -0400 [thread overview]
Message-ID: <20230916210131.78593-1-mlevedahl@gmail.com> (raw)
In-Reply-To: <xmqqy1h6auy7.fsf@gitster.g>
Earlier, commit aae9560a introduced search in $PATH to find executables
before running them, avoiding an issue where on Windows a same named
file in the current directory can be executed in preference to anything
in a directory in $PATH. This search is intended to find an absolute
path for a bare executable ( e.g, a function "foo") by finding the first
instance of "foo" in a directory given in $PATH, and this search works
correctly. The search is explicitly avoided for an executable named
with an absolute path (e.g., /bin/sh), and that works as well.
Unfortunately, the search is also applied to commands named with a
relative path. A hook script (or executable) $HOOK is usually located
relative to the project directory as .git/hooks/$HOOK. The search for
this will generally fail as that relative path will (probably) not exist
on any directory in $PATH. This means that git hooks in general now fail
to run. Considerable mayhem could occur should a directory on $PATH be
git controlled. If such a directory includes .git/hooks/$HOOK, that
repository's $HOOK will be substituted for the one in the current
project, with unknown consequences.
This lookup failure also occurs in worktrees linked to a remote .git
directory using git-new-workdir. However, a worktree using a .git file
pointing to a separate git directory apparently avoids this: in that
case the hook command is resolved to an absolute path before being
passed down to the code introduced in aae9560a.
Fix this by replacing the test for an "absolute" pathname to a check for
a command name having more than one pathname component. This limits the
search and absolute pathname resolution to bare commands. The new test
uses tcl's "file split" command. Experiments on Linux and Windows, using
tclsh, show that command names with relative and absolute paths always
give at least two components, while a bare command gives only one.
Linux: puts [file split {foo}] ==> foo
Linux: puts [file split {/foo}] ==> / foo
Linux: puts [file split {.git/foo}] ==> .git foo
Windows: puts [file split {foo}] ==> foo
Windows: puts [file split {c:\foo}] ==> c:/ foo
Windows: puts [file split {.git\foo}] ==> .git foo
The above results show the new test limits search and replacement
to bare commands on both Linux and Windows.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/git-gui.sh b/git-gui.sh
index 8bc8892..8603437 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -118,7 +118,7 @@ proc sanitize_command_line {command_line from_index} {
set i $from_index
while {$i < [llength $command_line]} {
set cmd [lindex $command_line $i]
- if {[file pathtype $cmd] ne "absolute"} {
+ if {[llength [file split $cmd]] < 2} {
set fullpath [_which $cmd]
if {$fullpath eq ""} {
throw {NOT-FOUND} "$cmd not found in PATH"
--
2.41.0.99.19
next prev parent reply other threads:[~2023-09-16 21:02 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-15 16:45 BUG: git-gui no longer executes hook scripts Mark Levedahl
2023-09-15 17:00 ` Junio C Hamano
2023-09-15 17:15 ` Junio C Hamano
2023-09-15 23:33 ` Mark Levedahl
2023-09-16 0:35 ` [PATCH] git-gui - re-enable use of " Mark Levedahl
2023-09-16 17:28 ` Junio C Hamano
2023-09-16 21:01 ` Mark Levedahl [this message]
2023-09-16 21:51 ` [PATCH v2] " Junio C Hamano
2023-09-17 19:22 ` Mark Levedahl
2023-09-17 19:24 ` [PATCH] git-gui - use git-hook, honor core.hooksPath Mark Levedahl
2023-09-18 15:27 ` Johannes Schindelin
2023-09-18 15:58 ` Junio C Hamano
2023-09-18 16:25 ` Mark Levedahl
2023-09-18 17:53 ` Junio C Hamano
2023-09-20 13:05 ` Pratyush Yadav
2023-09-20 15:30 ` Mark Levedahl
2023-09-20 16:58 ` Junio C Hamano
2023-09-20 15:49 ` Junio C Hamano
2023-09-18 15:26 ` [PATCH v2] git-gui - re-enable use of hook scripts Johannes Schindelin
2023-09-18 16:04 ` Junio C Hamano
2023-09-20 13:27 ` Pratyush Yadav
2023-09-16 4:45 ` BUG: git-gui no longer executes " Junio C Hamano
2023-09-16 12:56 ` Mark Levedahl
2023-09-16 14:49 ` Mark Levedahl
2023-09-16 17:31 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230916210131.78593-1-mlevedahl@gmail.com \
--to=mlevedahl@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=me@yadavpratyush.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).