git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matthias Aßhauer via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Pratyush Yadav" <me@yadavpratyush.com>,
	"Matthias Aßhauer" <mha1993@live.de>,
	"Matthias Aßhauer" <mha1993@live.de>
Subject: [PATCH] git-gui: add support for filenames starting with tilde
Date: Wed, 18 Oct 2023 08:50:43 +0000	[thread overview]
Message-ID: <pull.1599.git.1697619043944.gitgitgadget@gmail.com> (raw)

From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= <mha1993@live.de>

When git-gui encounters a file name starting with a tilde character (~),
TCL "helpfully" expands that tilde into a (probably non-existing) users
home directory. But in git-gui we're often not dealing with user supplied
paths, where such an expansion might be expected, but actual names of files.

Prevent TCL from doing tilde expansion on these literal filenames.

This fixes https://github.com/git-for-windows/git/issues/4349

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
---
    git-gui: add support for filenames starting with tilde
    
    I've originally submitted this patch as a pull request to Pratyush's
    git-gui repository [1] on March 23rd, but that hasn't received any
    feedback in almost seven months, so I'm resubmitting it on the mailing
    list, with an improved patch description.
    
    [1] https://github.com/prati0100/git-gui/pull/96

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1599%2Frimrul%2Fgit-gui-tilde-filenames-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1599/rimrul/git-gui-tilde-filenames-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1599

 git-gui/git-gui.sh    | 1 +
 git-gui/lib/diff.tcl  | 1 +
 git-gui/lib/index.tcl | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 3e5907a4609..e8d60cf3324 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -2273,6 +2273,7 @@ proc do_explore {} {
 # Open file relative to the working tree by the default associated app.
 proc do_file_open {file} {
 	global _gitworktree
+	if {[string index $file 0] eq {~}} {set file ./$file}
 	set explorer [get_explorer]
 	set full_file_path [file join $_gitworktree $file]
 	exec $explorer [file nativename $full_file_path] &
diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
index 871ad488c2a..b7686caa962 100644
--- a/git-gui/lib/diff.tcl
+++ b/git-gui/lib/diff.tcl
@@ -190,6 +190,7 @@ proc show_other_diff {path w m cont_info} {
 		set max_sz 100000
 		set type unknown
 		if {[catch {
+				if {[string index $path 0] eq {~}} {set path ./$path}
 				set type [file type $path]
 				switch -- $type {
 				directory {
diff --git a/git-gui/lib/index.tcl b/git-gui/lib/index.tcl
index d2ec24bd80e..2fbe1447975 100644
--- a/git-gui/lib/index.tcl
+++ b/git-gui/lib/index.tcl
@@ -617,7 +617,7 @@ proc delete_helper {path_list path_index deletion_errors batch_size \
 
 		set path [lindex $path_list $path_index]
 
-		set deletion_failed [catch {file delete -- $path} deletion_error]
+		set deletion_failed [catch {file delete -- ./$path} deletion_error]
 
 		if {$deletion_failed} {
 			lappend deletion_errors [list "$deletion_error"]

base-commit: a9ecda2788e229afc9b611acaa26d0d9d4da53ed
-- 
gitgitgadget

             reply	other threads:[~2023-10-18  8:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18  8:50 Matthias Aßhauer via GitGitGadget [this message]
2023-10-18 18:52 ` [PATCH] git-gui: add support for filenames starting with tilde 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=pull.1599.git.1697619043944.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=me@yadavpratyush.com \
    --cc=mha1993@live.de \
    /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).