git-gui: introduce function git_redir for git calls with redirections

Proc git invokes git and collects all output, which is it returns. We are going to treat command arguments and redirections differently to avoid passing arguments that look like redirections to the command accidentally. A few invocations also pass redirection operators as command arguments deliberately. Rewrite these cases to use a new function git_redir that takes two lists, one for the regular command arguments and one for the redirection operations. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Johannes Sixt committed May 4, 2025 at 20:26 UTC 99f7bc1af65fabab907bf35e645241f714e7386e
3 files changed +9 -5
git-gui.sh
+6 -2
@@ -621,7 +621,11 @@ proc _lappend_nice {cmd_var} {
621 }
622
623 proc git {args} {
624 - set fd [git_read $args]
624 + git_redir $args {}
625 +}
626 +
627 +proc git_redir {cmd redir} {
628 + set fd [git_read $cmd $redir]
629 fconfigure $fd -translation binary -encoding utf-8
630 set result [string trimright [read $fd] "\n"]
631 close $fd
@@ -1423,7 +1427,7 @@ proc PARENT {} {
1427 return $p
1428 }
1429 if {$empty_tree eq {}} {
1426 - set empty_tree [git mktree << {}]
1430 + set empty_tree [git_redir [list mktree] [list << {}]]
1431 }
1432 return $empty_tree
1433 }
lib/commit.tcl
+2 -2
@@ -388,8 +388,8 @@ A rescan will be automatically started now.
388 foreach p [concat $PARENT $MERGE_HEAD] {
389 lappend cmd -p $p
390 }
391 - lappend cmd <$msg_p
392 - if {[catch {set cmt_id [eval git $cmd]} err]} {
391 + set msgtxt [list <$msg_p]
392 + if {[catch {set cmt_id [git_redir $cmd $msgtxt]} err]} {
393 catch {file delete $msg_p}
394 error_popup [strcat [mc "commit-tree failed:"] "\n\n$err"]
395 ui_status [mc "Commit failed."]
lib/merge.tcl
+1 -1
@@ -118,7 +118,7 @@ method _start {} {
118 set cmd [list git]
119 lappend cmd merge
120 lappend cmd --strategy=recursive
121 - lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]]
121 + lappend cmd [git_redir [list fmt-merge-msg] [list <[gitdir FETCH_HEAD]]]
122 lappend cmd HEAD
123 lappend cmd $name
124 }