git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v0 4/4] git-gui - use mkshortcut on Cygwin

From
Mark Levedahl <mlevedahl@gmail.com>
Date
Jun 24, 2023, 21:23 UTC
Message-ID
<20230624212347.179656-5-mlevedahl@gmail.com>
In-Reply-To
<20230624212347.179656-1-mlevedahl@gmail.com>

Prior to 2012, git-gui enabled the "Repository->Create Desktop Icon" item on Cygwin, offering to create a shortcut that starts git-gui on a particular repository. The original code for this in lib/win32.tcl, shared with Git for Windows support, requires Windows pathnames, while git-gui must use unix pathnames with the unix/X11 Tcl/Tk since 2012. The ability to use this from Cygwin was removed in a previous patch.

Cygwin's default installation provides /bin/mkshortcut for creating desktop shortuts, this is compatible with exec under tcl, and understands Cygwin's unix pathnames. So, teach git-gui to use mkshortcut on Cygwin, leaving lib/win32.tcl as Git for Windows specific support.

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 pre-2012 code includes the full pathname of the git-gui creating the shortcut (rather than using the system git-gui), 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 this chain. Instead, use "git gui", thus defaulting to the system git and avoiding both issues.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
 git-gui.sh       |  4 ++++
 lib/shortcut.tcl | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
diff --git a/git-gui.sh b/git-gui.sh
index 523770a..5c13521 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2836,6 +2836,10 @@ if {[is_enabled multicommit]} {
 		.mbar.repository add command \
 			-label [mc "Create Desktop Icon"] \
 			-command do_windows_shortcut
+	} elseif {[is_Cygwin]} {
+		.mbar.repository add command \
+			-label [mc "Create Desktop Icon"] \
+			-command do_cygwin_shortcut
 	} elseif {[is_MacOSX]} {
 		.mbar.repository add command \
 			-label [mc "Create Desktop Icon"] \
diff --git a/lib/shortcut.tcl b/lib/shortcut.tcl
index 1d8374b..6c2a99e 100644
--- a/lib/shortcut.tcl
+++ b/lib/shortcut.tcl
@@ -26,6 +26,44 @@ proc do_windows_shortcut {} {
 	}
 }
 
+proc do_cygwin_shortcut {} {
+	global argv0 _gitworktree oguilib
+
+	if {[catch {
+		set desktop [exec cygpath \
+			--desktop]
+		}]} {
+			set desktop .
+	}
+	set fn [tk_getSaveFile \
+		-parent . \
+		-title [mc "%s (%s): Create Desktop Icon" [appname] [reponame]] \
+		-initialdir $desktop \
+		-initialfile "Git [reponame].lnk"]
+	if {$fn != {}} {
+		if {[file extension $fn] ne {.lnk}} {
+			set fn ${fn}.lnk
+		}
+		if {[catch {
+				set repodir [file normalize $_gitworktree]
+				set shargs {-c \
+					"CHERE_INVOKING=1 \
+					source /etc/profile; \
+					git gui"}
+				exec /bin/mkshortcut.exe \
+					-a $shargs \
+					-d "git-gui on $repodir" \
+					-i $oguilib/git-gui.ico \
+					-n $fn \
+					-s min \
+					-w $repodir \
+					/bin/sh.exe
+			} err]} {
+			error_popup [strcat [mc "Cannot write shortcut:"] "\n\n$err"]
+		}
+	}
+}
+
 proc do_macosx_app {} {
 	global argv0 env
 
-- 
2.41.0.99.19
Previous: Mark LevedahlNext: Junio C Hamano
Message 7 of 27 in “Remove obsolete Cygwin support from git-gui”
  1. 0/4 Remove obsolete Cygwin support from git-guiMark Levedahl, Jun 24, 2023
  2. 1/4 git gui Makefile - remove Cygwin modiificationsMark Levedahl, Jun 24, 2023
  3. 2/4 git-gui - remove obsolete Cygwin specific codeMark Levedahl, Jun 24, 2023
  4. Eric SunshineJun 25, 2023
  5. Mark LevedahlJun 25, 2023
  6. 3/4 git-gui - use cygstart to browse on CygwinMark Levedahl, Jun 24, 2023
  7. 4/4 git-gui - use mkshortcut on CygwinMark Levedahl, Jun 24, 2023
  8. Junio C HamanoJun 24, 2023
  9. Junio C HamanoJun 24, 2023
  10. Mark LevedahlJun 25, 2023
  11. Mark LevedahlJun 25, 2023
  12. Mark LevedahlJun 25, 2023
  13. Junio C HamanoJun 25, 2023
  14. Mark LevedahlJun 25, 2023
  15. Junio C HamanoJun 26, 2023
  16. Mark LevedahlJun 26, 2023
  17. 0/4 Remove obsolete Cygwin support from git-guiMark Levedahl, Jun 26, 2023
  18. 1/4 git gui Makefile - remove Cygwin modificationsMark Levedahl, Jun 26, 2023
  19. 2/4 git-gui - remove obsolete Cygwin specific codeMark Levedahl, Jun 26, 2023
  20. 3/4 git-gui - use cygstart to browse on CygwinMark Levedahl, Jun 26, 2023
  21. 4/4 git-gui - use mkshortcut on CygwinMark Levedahl, Jun 26, 2023
  22. Johannes SchindelinJun 27, 2023
  23. Junio C HamanoJun 27, 2023
  24. Mark LevedahlAug 5, 2023
  25. Pratyush YadavAug 24, 2023
  26. Mark LevedahlAug 29, 2023
  27. Junio C HamanoAug 29, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.