From cc4b1c0213ad2d99121135125b8c2ea630bebe3d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 6 Nov 2006 23:47:05 -0500 Subject: [PATCH] git-gui: Worked around environment variable problems on Windows. Apparently the Cygwin tclsh/wish executables don't pass the environment that they inherited onto any children that they invoke. This causes a problem for some users during 'git fetch' or 'git push' as critical environment variables like GIT_SSH and SSH_AUTH_SOCK aren't available to the git processes. So we work around this by forcing sh to start a login shell, thus reloading the user's environment, then cd to the current directory, and finally start the requested process. Of course this won't correctly handle any transient environment variables that were inherited but were not supplied by the user's login shell. Signed-off-by: Shawn O. Pearce --- git-gui | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/git-gui b/git-gui index a43fb2f66..be361dec1 100755 --- a/git-gui +++ b/git-gui @@ -92,7 +92,7 @@ proc update_status {{final Ready.}} { } if {![$ui_comm edit modified] - || [string trim [$ui_comm get 0.0 end]] == {}} { + || [string trim [$ui_comm get 0.0 end]] == {}} { if {[load_message GITGUI_MSG]} { } elseif {[load_message MERGE_MSG]} { } elseif {[load_message SQUASH_MSG]} { @@ -591,25 +591,19 @@ proc commit_stage2 {fd_wt curHEAD msg} { proc fetch_from {remote} { set w [new_console "fetch $remote" \ "Fetching new changes from $remote"] - set cmd [list | git fetch] - lappend -v + set cmd [list git fetch] + lappend cmd -v lappend cmd $remote - lappend cmd |& cat - set fd_f [open $cmd r] - fconfigure $fd_f -blocking 0 -translation auto - fileevent $fd_f readable [list console_read $w $fd_f] + console_exec $w $cmd } proc push_to {remote} { set w [new_console "push $remote" \ "Pushing changes to $remote"] - set cmd [list | git push] + set cmd [list git push] lappend -v lappend cmd $remote - lappend cmd |& cat - set fd_f [open $cmd r] - fconfigure $fd_f -blocking 0 -translation auto - fileevent $fd_f readable [list console_read $w $fd_f] + console_exec $w $cmd } ###################################################################### @@ -1043,6 +1037,26 @@ proc new_console {short_title long_title} { return $w } +proc console_exec {w cmd} { + global tcl_platform + + # -- Windows tosses the enviroment when we exec our child. + # But most users need that so we have to relogin. :-( + # + if {$tcl_platform(platform) == {windows}} { + set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"] + } + + # -- Tcl won't let us redirect both stdout and stderr to + # the same pipe. So pass it through cat... + # + set cmd [concat | $cmd |& cat] + + set fd_f [open $cmd r] + fconfigure $fd_f -blocking 0 -translation auto + fileevent $fd_f readable [list console_read $w $fd_f] +} + proc console_read {w fd} { $w.m.t conf -state normal while {[gets $fd line] >= 0} { @@ -1050,6 +1064,7 @@ proc console_read {w fd} { $w.m.t insert end "\n" } $w.m.t conf -state disabled + $w.m.t see end if {[eof $fd]} { close $fd @@ -1062,6 +1077,7 @@ proc console_read {w fd} { ## ui commands set starting_gitk_msg {Please wait... Starting gitk...} + proc do_gitk {} { global tcl_platform ui_status_value starting_gitk_msg @@ -1072,7 +1088,7 @@ proc do_gitk {} { } } - if {$tcl_platform(platform) == "windows"} { + if {$tcl_platform(platform) == {windows}} { exec sh -c gitk & } else { exec gitk & -- 2.26.2