From b76a5a854bfae6542eec333365b218c5bc0fdf5b Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Sun, 13 Apr 2025 14:15:08 -0400 Subject: git-gui: do not add directories to PATH on Windows git-gui on Windows prepends three directories to PATH so does not honor PATH as configured. This can have undesirable consequences, for instance by preventing use of a different git for testing. This also provides at best a subset of the configuration included with Git for Windows (g4w), so is neither necessary nor sufficient there. Since commit be700fe3, git-gui.sh adds its directory to the front of PATH: this is essentially adding $(git --execdir) to the path, this is long deprecated as git moved to using "dashless" subcommands. The windows/git-gui.sh wrapper file, since commit 99fe594d, adds two directories relative to its installed location to PATH, and does so without checking that either exists or is needed. The above modifications were made before the Git For Windows project took responsibility for distributing a working solution on Windows. g4w assures a correct configuration on Windows without these, and doing so requires more than the above modifications. See [1] for a more thorough treatment. git-gui does not modify PATH on any platform except on Windows, and doing so is not needed by g4w. Let's stop modifying PATH on Windows as well. [1] https://gitforwindows.org/git-wrapper.html Signed-off-by: Mark Levedahl --- git-gui.sh | 6 ------ windows/git-gui.sh | 12 ++---------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index c77c05edde..8d97817908 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -87,12 +87,6 @@ if {[is_Windows]} { set _search_exe {} } -if {[is_Windows]} { - set gitguidir [file dirname [info script]] - regsub -all ";" $gitguidir "\\;" gitguidir - set env(PATH) "$gitguidir;$env(PATH)" -} - set _search_path {} set _path_seen [dict create] foreach p [split $env(PATH) $_path_sep] { diff --git a/windows/git-gui.sh b/windows/git-gui.sh index b1845c5055..38debe376c 100755 --- a/windows/git-gui.sh +++ b/windows/git-gui.sh @@ -13,13 +13,5 @@ if { $argc >=2 && [lindex $argv 0] == "--working-dir" } { incr argc -2 } -set basedir [file dirname \ - [file dirname \ - [file dirname [info script]]]] -set bindir [file join $basedir bin] -set bindir "$bindir;[file join $basedir mingw bin]" -regsub -all ";" $bindir "\\;" bindir -set env(PATH) "$bindir;$env(PATH)" -unset bindir - -source [file join [file dirname [info script]] git-gui.tcl] +set thisdir [file normalize [file dirname [info script]]] +source [file join $thisdir git-gui.tcl] -- cgit v1.3-5-g9baa From e80065ecd700334fbc9f1de31320b83a894cfa06 Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Tue, 20 May 2025 10:08:44 -0400 Subject: git-gui: let nice work on Windows git-gui runs blame and diff commands with nice by default. On Unix, nice is accepted if found and it will run git. Commit ff9db6c79d ("On Windows, avoid git-gui to call Cygwin's nice utility", 2010-10-05) rejects nice if not collocated with git. In Git for Windows' (g4w) POSIX path name space, nice and git are found in different directories: $ which git /mingw64/bin/git $ which nice /usr/bin/nice Thus, git-gui will not use nice in the supported Windows configuration. Commit ff9db6c79d justifies the collocation requirement as avoiding problems in a mixed MSYS and Cygwin configuration: such configurations are not supported by either project as they are known to cause many problems. So, let's revert ff9db6c79d and let git-gui work correctly in the supported configuration. Signed-off-by: Mark Levedahl --- git-gui.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 8d97817908..2b5b596400 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -638,8 +638,6 @@ proc _lappend_nice {cmd_var} { set _nice [_which nice] if {[catch {safe_exec [list $_nice git version]}]} { set _nice {} - } elseif {[is_Windows] && [file dirname $_nice] ne [file dirname $::_git]} { - set _nice {} } } if {$_nice ne {}} { -- cgit v1.3-5-g9baa From 3c8e1fe0eaaa976aace243680b825099f687a9bd Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Sun, 13 Apr 2025 14:31:52 -0400 Subject: git-gui: Windows tk_getSaveFile is not useful for shortcuts git-gui invokes the tk_getSaveFile dialog to determine the full path-name of the shortcut file to create. But, on Windows, this dialog always dereferences a shortcut (.lnk) file, as this is essentially a soft-link to its target. If the shortcut file already exists, the dialog returns the path-name of the target (i.e., GIT/cmd/git-gui.exe), and not the desired shortcut file selected by the user. There is no Windows file chooser available in Tcl/Tk that does not dereference .lnk files, so this patch avoids using a dialog: the shortcut to be created is on the desktop and named as "Git + Repository Name". If this .lnk file already exists, the user must give permission to overwrite it or the process terminates. Signed-off-by: Mark Levedahl --- lib/shortcut.tcl | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/shortcut.tcl b/lib/shortcut.tcl index 1d01d9cbfa..feaccbdd1d 100644 --- a/lib/shortcut.tcl +++ b/lib/shortcut.tcl @@ -3,27 +3,38 @@ proc do_windows_shortcut {} { global _gitworktree - set fn [tk_getSaveFile \ - -parent . \ - -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \ - -initialfile "Git [reponame].lnk"] - if {$fn != {}} { - if {[file extension $fn] ne {.lnk}} { - set fn ${fn}.lnk - } - # Use git-gui.exe if available (ie: git-for-windows) - set cmdLine [list [_which git-gui]] - if {$cmdLine eq {}} { - set cmdLine [list [info nameofexecutable] \ - [file normalize $::argv0]] - } - if {[catch { - win32_create_lnk $fn $cmdLine \ - [file normalize $_gitworktree] - } err]} { - error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"] + + set desktop [safe_exec [list cygpath -mD]] + set link_file "Git [reponame].lnk" + set link_path [file normalize [file join $desktop $link_file]] + + # on Windows, tk_getSaveFile dereferences .lnk files, so no simple + # filename chooser is available. Use the default or quit. + if {[file exists $link_path]} { + set answer [tk_messageBox \ + -type yesno \ + -title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \ + -default yes \ + -message [mc "Replace existing shortcut: %s?" $link_file]] + if {$answer == no} { + return } } + + # Use git-gui.exe if found, fall back to wish + launcher + set link_arguments {} + set link_target [_which git-gui] + if {![file executable $link_target]} { + set link_target [file normalize [info nameofexecutable]] + set link_arguments [file normalize $::argv0] + } + set cmdLine [list $link_target $link_arguments] + if {[catch { + win32_create_lnk $link_path $cmdLine \ + [file normalize $_gitworktree] + } err]} { + error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"] + } } proc do_cygwin_shortcut {} { -- cgit v1.3-5-g9baa From 158800ac9c792b875b2cd138a1ecbfb14fa6a71a Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Sun, 13 Apr 2025 14:45:04 -0400 Subject: git-gui: use /cmd/git-gui.exe for shortcut git-gui on Windows creates a shortcut that presumes the git-gui script will run on the basic Windows environment as configured. But, Git for Windows uses wrapper scripts to launch executables, assuring the environment is correct (see [1] for details). The launcher for git-gui is /cmd/git-gui.exe, is not on PATH, and is not detected or used by the current shortcut code. Let's look for this before trying the existing approaches. [1] https://gitforwindows.org/git-wrapper.html Signed-off-by: Mark Levedahl --- lib/shortcut.tcl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/shortcut.tcl b/lib/shortcut.tcl index feaccbdd1d..431665059e 100644 --- a/lib/shortcut.tcl +++ b/lib/shortcut.tcl @@ -23,7 +23,10 @@ proc do_windows_shortcut {} { # Use git-gui.exe if found, fall back to wish + launcher set link_arguments {} - set link_target [_which git-gui] + set link_target [safe_exec [list cygpath -m /cmd/git-gui.exe]] + if {![file executable $link_target]} { + set link_target [_which git-gui] + } if {![file executable $link_target]} { set link_target [file normalize [info nameofexecutable]] set link_arguments [file normalize $::argv0] -- cgit v1.3-5-g9baa