git-gui: Improve the Windows and Mac OS X shortcut creators
We now embed any GIT_* and SSH_* environment variables as well as the path to the git wrapper executable into the Mac OS X .app file. This should allow us to restore the environment properly when we restart. We also try to use proper Bourne shell single quoting when we can, as this avoids any sort of problems that might occur due to a path containing shell metacharacters. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 9, 2007 at 03:28 UTC
7eafa2f1578e605e1e68d8ccba9d600cc6b89173
2 files changed
+31
-21
git-gui.sh
+5
@@ -475,6 +475,11 @@ proc git_write {args} {
475
return [open [concat $opt $cmdp $args] w]
476
}
477
478
+proc sq {value} {
479
+ regsub -all ' $value "'\\''" value
480
+ return "'$value'"
481
+}
482
+
483
proc load_current_branch {} {
484
global current_branch is_detached
485
lib/shortcut.tcl
+26
-21
@@ -13,10 +13,11 @@ proc do_windows_shortcut {} {
13
set fn ${fn}.bat
14
}
15
if {[catch {
16
+ set ge [file normalize [file dirname $::_git]]
17
set fd [open $fn w]
18
puts $fd "@ECHO Entering [reponame]"
19
puts $fd "@ECHO Starting git-gui... please wait..."
19
- puts $fd "@SET PATH=[file normalize [gitexec]];%PATH%"
20
+ puts $fd "@SET PATH=$ge;%PATH%"
21
puts $fd "@SET GIT_DIR=[file normalize [gitdir]]"
22
puts -nonewline $fd "@\"[info nameofexecutable]\""
23
puts $fd " \"[file normalize $argv0]\""
@@ -62,17 +63,11 @@ proc do_cygwin_shortcut {} {
63
--unix \
64
--absolute \
65
[gitdir]]
65
- set gw [exec cygpath \
66
- --windows \
67
- --absolute \
68
- [file dirname [gitdir]]]
69
- regsub -all ' $me "'\\''" me
70
- regsub -all ' $gd "'\\''" gd
71
- puts $fd "@ECHO Entering $gw"
66
+ puts $fd "@ECHO Entering [reponame]"
67
puts $fd "@ECHO Starting git-gui... please wait..."
68
puts -nonewline $fd "@\"$sh\" --login -c \""
74
- puts -nonewline $fd "GIT_DIR='$gd'"
75
- puts -nonewline $fd " '$me'"
69
+ puts -nonewline $fd "GIT_DIR=[sq [$gd]]"
70
+ puts -nonewline $fd " [sq $me]"
71
puts $fd "&\""
72
close $fd
73
} err]} {
@@ -90,6 +85,9 @@ proc do_macosx_app {} {
85
-initialdir [file join $env(HOME) Desktop] \
86
-initialfile "Git [reponame].app"]
87
if {$fn != {}} {
88
+ if {[file extension $fn] ne {.app}} {
89
+ set fn ${fn}.app
90
+ }
91
if {[catch {
92
set Contents [file join $fn Contents]
93
set MacOS [file join $Contents MacOS]
@@ -123,20 +121,27 @@ proc do_macosx_app {} {
121
close $fd
122
123
set fd [open $exe w]
126
- set gd [file normalize [gitdir]]
127
- set ep [file normalize [gitexec]]
128
- regsub -all ' $gd "'\\''" gd
129
- regsub -all ' $ep "'\\''" ep
124
puts $fd "#!/bin/sh"
131
- foreach name [array names env] {
132
- if {[string match GIT_* $name]} {
133
- regsub -all ' $env($name) "'\\''" v
134
- puts $fd "export $name='$v'"
125
+ foreach name [lsort [array names env]] {
126
+ set value $env($name)
127
+ switch -- $name {
128
+ GIT_DIR { set value [file normalize [gitdir]] }
129
+ }
130
+
131
+ switch -glob -- $name {
132
+ SSH_* -
133
+ GIT_* {
134
+ puts $fd "if test \"z\$$name\" = z; then"
135
+ puts $fd " export $name=[sq $value]"
136
+ puts $fd "fi &&"
137
+ }
138
}
139
}
137
- puts $fd "export PATH='$ep':\$PATH"
138
- puts $fd "export GIT_DIR='$gd'"
139
- puts $fd "exec [file normalize $argv0]"
140
+ puts $fd "export PATH=[sq [file dirname $::_git]]:\$PATH &&"
141
+ puts $fd "cd [sq [file normalize [pwd]]] &&"
142
+ puts $fd "exec \\"
143
+ puts $fd " [sq [info nameofexecutable]] \\"
144
+ puts $fd " [sq [file normalize $argv0]]"
145
close $fd
146
147
file attributes $exe -permissions u+x,g+x,o+x