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>
This commit is contained in:
Johannes Sixt
2025-05-04 20:26:11 +02:00
committed by Taylor Blau
parent 60b0ba0a04
commit 99f7bc1af6
3 changed files with 9 additions and 5 deletions

View File

@@ -621,7 +621,11 @@ proc _lappend_nice {cmd_var} {
}
proc git {args} {
set fd [git_read $args]
git_redir $args {}
}
proc git_redir {cmd redir} {
set fd [git_read $cmd $redir]
fconfigure $fd -translation binary -encoding utf-8
set result [string trimright [read $fd] "\n"]
close $fd
@@ -1423,7 +1427,7 @@ proc PARENT {} {
return $p
}
if {$empty_tree eq {}} {
set empty_tree [git mktree << {}]
set empty_tree [git_redir [list mktree] [list << {}]]
}
return $empty_tree
}

View File

@@ -388,8 +388,8 @@ A rescan will be automatically started now.
foreach p [concat $PARENT $MERGE_HEAD] {
lappend cmd -p $p
}
lappend cmd <$msg_p
if {[catch {set cmt_id [eval git $cmd]} err]} {
set msgtxt [list <$msg_p]
if {[catch {set cmt_id [git_redir $cmd $msgtxt]} err]} {
catch {file delete $msg_p}
error_popup [strcat [mc "commit-tree failed:"] "\n\n$err"]
ui_status [mc "Commit failed."]

View File

@@ -118,7 +118,7 @@ method _start {} {
set cmd [list git]
lappend cmd merge
lappend cmd --strategy=recursive
lappend cmd [git fmt-merge-msg <[gitdir FETCH_HEAD]]
lappend cmd [git_redir [list fmt-merge-msg] [list <[gitdir FETCH_HEAD]]]
lappend cmd HEAD
lappend cmd $name
}