git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Levedahl <mlevedahl@gmail.com>
To: git@vger.kernel.org
Cc: adam@dinwoodie.org, me@yadavpratyush.com,
	johannes.schindelin@gmx.de, Mark Levedahl <mlevedahl@gmail.com>
Subject: [PATCH v0 4/4] git-gui - use mkshortcut on Cygwin
Date: Sat, 24 Jun 2023 17:23:47 -0400	[thread overview]
Message-ID: <20230624212347.179656-5-mlevedahl@gmail.com> (raw)
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


  parent reply	other threads:[~2023-06-24 21:24 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-24 21:23 [PATCH v0 0/4] Remove obsolete Cygwin support from git-gui Mark Levedahl
2023-06-24 21:23 ` [PATCH v0 1/4] git gui Makefile - remove Cygwin modiifications Mark Levedahl
2023-06-24 21:23 ` [PATCH v0 2/4] git-gui - remove obsolete Cygwin specific code Mark Levedahl
2023-06-25  2:56   ` Eric Sunshine
2023-06-25 11:29     ` Mark Levedahl
2023-06-24 21:23 ` [PATCH v0 3/4] git-gui - use cygstart to browse on Cygwin Mark Levedahl
2023-06-24 21:23 ` Mark Levedahl [this message]
2023-06-24 23:30 ` [PATCH v0 0/4] Remove obsolete Cygwin support from git-gui Junio C Hamano
2023-06-24 23:35   ` Junio C Hamano
2023-06-25 11:28     ` Mark Levedahl
2023-06-25 11:26   ` Mark Levedahl
2023-06-25 12:10     ` Mark Levedahl
2023-06-25 15:46     ` Junio C Hamano
2023-06-25 17:01       ` Mark Levedahl
2023-06-26 15:52         ` Junio C Hamano
2023-06-26 16:55           ` Mark Levedahl
2023-06-26 16:53 ` [PATCH v1 " Mark Levedahl
2023-06-26 16:53   ` [PATCH v1 1/4] git gui Makefile - remove Cygwin modifications Mark Levedahl
2023-06-26 16:53   ` [PATCH v1 2/4] git-gui - remove obsolete Cygwin specific code Mark Levedahl
2023-06-26 16:53   ` [PATCH v1 3/4] git-gui - use cygstart to browse on Cygwin Mark Levedahl
2023-06-26 16:53   ` [PATCH v1 4/4] git-gui - use mkshortcut " Mark Levedahl
2023-06-27 11:51   ` [PATCH v1 0/4] Remove obsolete Cygwin support from git-gui Johannes Schindelin
2023-06-27 17:52   ` Junio C Hamano
2023-08-05 14:47     ` Mark Levedahl
2023-08-24 15:54       ` Pratyush Yadav
2023-08-29 16:03     ` Mark Levedahl
2023-08-29 16:18       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230624212347.179656-5-mlevedahl@gmail.com \
    --to=mlevedahl@gmail.com \
    --cc=adam@dinwoodie.org \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=me@yadavpratyush.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).