]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: cleanup git-bash menu item
authorMark Levedahl <mlevedahl@gmail.com>
Mon, 7 Apr 2025 21:12:56 +0000 (17:12 -0400)
committerTaylor Blau <me@ttaylorr.com>
Fri, 23 May 2025 21:04:23 +0000 (17:04 -0400)
git-gui on Git for Windows creates a menu item to start a git-bash
session for the current repository. This menu-item works as desired when
git-gui is installed in the Git for Windows (g4w) distribution, but
not when run from a different location such as normally done in
development. The reason is that git-bash's location is known to be
'/git-bash' in the Unix pathname space known to MSYS, but this is not
known in the Windows pathname space. Instead, git-gui derives a pathname
for git-bash assuming it is at a known relative location.

If git-gui is run from a different directory than assumed in g4w, the
relative location changes, and git-gui resorts to running a generic bash
login session in a Windows console.

But, the MSYS system underlying Git for Windows includes the 'cygpath'
utility to convert between Unix and Windows pathnames. Let's use this so
git-bash's Windows pathname is determined directly from /git-bash.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
git-gui.sh

index 3bfe4364c726728729839c3bcdc79fdc8978b0e9..570c236f57f3c72c50201f33dbd969269a023509 100755 (executable)
@@ -2759,17 +2759,16 @@ if {![is_bare]} {
 
 if {[is_Windows]} {
        # Use /git-bash.exe if available
-       set normalized [file normalize $::argv0]
-       regsub "/mingw../libexec/git-core/git-gui$" \
-               $normalized "/git-bash.exe" cmdLine
-       if {$cmdLine != $normalized && [file exists $cmdLine]} {
-               set cmdLine [list "Git Bash" $cmdLine &]
+       set _git_bash [exec cygpath -m /git-bash.exe]
+       if {[file executable $_git_bash]} {
+               set _bash_cmdline [list "Git Bash" $_git_bash &]
        } else {
-               set cmdLine [list "Git Bash" bash --login -l &]
+               set _bash_cmdline [list "Git Bash" bash --login -l &]
        }
        .mbar.repository add command \
                -label [mc "Git Bash"] \
-               -command {eval exec [list [_which cmd] /c start] $cmdLine}
+               -command {eval exec [list [_which cmd] /c start] $_bash_cmdline}
+       unset _git_bash
 }
 
 if {[is_Windows] || ![is_bare]} {