Skip to content

Commit b85c5a4

Browse files
mark987prati0100
authored andcommitted
git-gui - use mkshortcut on Cygwin
git-gui enables the "Repository->Create Desktop Icon" item on Cygwin, offering to create a shortcut that starts git-gui on the current repository. The code in do_cygwin_shortcut invokes function win32_create_lnk to create the shortcut. This latter function is shared between Cygwin and Git For Windows and expects Windows rather than unix pathnames, though do_cygwin_shortcut provides unix pathnames. Also, this function tries to invoke the Windows Script Host to run a javascript snippet, but this fails under Cygwin's Tcl. So, win32_create_lnk just does not support Cygwin. However, Cygwin's default installation provides /bin/mkshortcut for creating desktop shortcuts. This is compatible with exec under Cygwin's Tcl, understands Cygwin's unix pathnames, and avoids the need for shell escapes to encode troublesome paths. So, teach git-gui to use mkshortcut on Cygwin, leaving win32_create_lnk unchanged and for exclusive use by Git For Windows. Notes: "CHERE_INVOKING=1" is recognized by Cygwin's /etc/profile and prevents a "chdir $HOME", leaving the shell in the working directory specified by the shortcut. That directory is written directly by mkshortcut eliminating any problems with shell escapes and quoting. The code being replaced includes the full pathname of the git-gui creating the shortcut, but that git-gui might not be compatible with the git found after /etc/profile sets the path, and might have a pathname that defies encoding using shell escapes that can survive the multiple incompatible interpreters involved in the chain of creating and using this shortcut. The new code uses bare "git gui" as the command to execute, thus using the system git to launch the system git-gui, and avoiding both issues. Signed-off-by: Mark Levedahl <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Pratyush Yadav <[email protected]>
1 parent 4ed23c3 commit b85c5a4

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

lib/shortcut.tcl

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ proc do_windows_shortcut {} {
2727
}
2828

2929
proc do_cygwin_shortcut {} {
30-
global argv0 _gitworktree
30+
global argv0 _gitworktree oguilib
3131

3232
if {[catch {
3333
set desktop [exec cygpath \
34-
--windows \
35-
--absolute \
36-
--long-name \
3734
--desktop]
3835
}]} {
3936
set desktop .
@@ -48,19 +45,19 @@ proc do_cygwin_shortcut {} {
4845
set fn ${fn}.lnk
4946
}
5047
if {[catch {
51-
set sh [exec cygpath \
52-
--windows \
53-
--absolute \
54-
/bin/sh.exe]
55-
set me [exec cygpath \
56-
--unix \
57-
--absolute \
58-
$argv0]
59-
win32_create_lnk $fn [list \
60-
$sh -c \
61-
"CHERE_INVOKING=1 source /etc/profile;[sq $me] &" \
62-
] \
63-
[file normalize $_gitworktree]
48+
set repodir [file normalize $_gitworktree]
49+
set shargs {-c \
50+
"CHERE_INVOKING=1 \
51+
source /etc/profile; \
52+
git gui"}
53+
exec /bin/mkshortcut.exe \
54+
--arguments $shargs \
55+
--desc "git-gui on $repodir" \
56+
--icon $oguilib/git-gui.ico \
57+
--name $fn \
58+
--show min \
59+
--workingdir $repodir \
60+
/bin/sh.exe
6461
} err]} {
6562
error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"]
6663
}

0 commit comments

Comments
 (0)