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 <spearce@spearce.org>
Shawn O. Pearce committed
Nov 6, 2006 at 23:47 UTC
cc4b1c0213ad2d99121135125b8c2ea630bebe3d
1 file changed
+29
-13
git-gui
+29
-13
@@ -92,7 +92,7 @@ proc update_status {{final Ready.}} {
92
}
93
94
if {![$ui_comm edit modified]
95
- || [string trim [$ui_comm get 0.0 end]] == {}} {
95
+ || [string trim [$ui_comm get 0.0 end]] == {}} {
96
if {[load_message GITGUI_MSG]} {
97
} elseif {[load_message MERGE_MSG]} {
98
} elseif {[load_message SQUASH_MSG]} {
@@ -591,25 +591,19 @@ proc commit_stage2 {fd_wt curHEAD msg} {
591
proc fetch_from {remote} {
592
set w [new_console "fetch $remote" \
593
"Fetching new changes from $remote"]
594
- set cmd [list | git fetch]
595
- lappend -v
594
+ set cmd [list git fetch]
595
+ lappend cmd -v
596
lappend cmd $remote
597
- lappend cmd |& cat
598
- set fd_f [open $cmd r]
599
- fconfigure $fd_f -blocking 0 -translation auto
600
- fileevent $fd_f readable [list console_read $w $fd_f]
597
+ console_exec $w $cmd
598
}
599
600
proc push_to {remote} {
601
set w [new_console "push $remote" \
602
"Pushing changes to $remote"]
606
- set cmd [list | git push]
603
+ set cmd [list git push]
604
lappend -v
605
lappend cmd $remote
609
- lappend cmd |& cat
610
- set fd_f [open $cmd r]
611
- fconfigure $fd_f -blocking 0 -translation auto
612
- fileevent $fd_f readable [list console_read $w $fd_f]
606
+ console_exec $w $cmd
607
}
608
609
######################################################################
@@ -1043,6 +1037,26 @@ proc new_console {short_title long_title} {
1037
return $w
1038
}
1039
1040
+proc console_exec {w cmd} {
1041
+ global tcl_platform
1042
+
1043
+ # -- Windows tosses the enviroment when we exec our child.
1044
+ # But most users need that so we have to relogin. :-(
1045
+ #
1046
+ if {$tcl_platform(platform) == {windows}} {
1047
+ set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
1048
+ }
1049
+
1050
+ # -- Tcl won't let us redirect both stdout and stderr to
1051
+ # the same pipe. So pass it through cat...
1052
+ #
1053
+ set cmd [concat | $cmd |& cat]
1054
+
1055
+ set fd_f [open $cmd r]
1056
+ fconfigure $fd_f -blocking 0 -translation auto
1057
+ fileevent $fd_f readable [list console_read $w $fd_f]
1058
+}
1059
+
1060
proc console_read {w fd} {
1061
$w.m.t conf -state normal
1062
while {[gets $fd line] >= 0} {
@@ -1050,6 +1064,7 @@ proc console_read {w fd} {
1064
$w.m.t insert end "\n"
1065
}
1066
$w.m.t conf -state disabled
1067
+ $w.m.t see end
1068
1069
if {[eof $fd]} {
1070
close $fd
@@ -1062,6 +1077,7 @@ proc console_read {w fd} {
1077
## ui commands
1078
1079
set starting_gitk_msg {Please wait... Starting gitk...}
1080
+
1081
proc do_gitk {} {
1082
global tcl_platform ui_status_value starting_gitk_msg
1083
@@ -1072,7 +1088,7 @@ proc do_gitk {} {
1088
}
1089
}
1090
1075
- if {$tcl_platform(platform) == "windows"} {
1091
+ if {$tcl_platform(platform) == {windows}} {
1092
exec sh -c gitk &
1093
} else {
1094
exec gitk &