Skip to content

Commit

Permalink
git-gui: add support for filenames starting with tilde
Browse files Browse the repository at this point in the history
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 git-for-windows#4349

Signed-off-by: Matthias Aßhauer <[email protected]>
  • Loading branch information
rimrul committed Oct 18, 2023
1 parent a9ecda2 commit a485c34
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions git-gui/git-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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] &
Expand Down
1 change: 1 addition & 0 deletions git-gui/lib/diff.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion git-gui/lib/index.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit a485c34

Please sign in to comment.