From 6636903237b2cdad345578ba7ce10f3260da76b8 Mon Sep 17 00:00:00 2001 From: Tobias Boesch Date: Wed, 4 Sep 2024 13:35:24 +0200 Subject: [PATCH] git gui: add directly calling merge tool from gitconfig git gui can open a merge tool when conflicts are detected (Right click in the diff of the file with conflicts). The merge tools that are allowed to use are hard coded into git gui. If one wants to add a new merge tool it has to be added to git gui through a source code change. This is not convenient in comparison to how it works in git (without gui). git itself has configuration options for a merge tools path and command in the git config. New merge tools can be set up there without a source code change. Those options are used only by pure git in contrast to git gui. git calls the configured merge tools directly from the config while git Gui doesn't. With this change git gui can call merge tools configured in the gitconfig directly without a change in git gui source code. It needs a configured merge.tool and a configured mergetool.cmd config entry. gitconfig example: [merge] tool = vscode [mergetool "vscode"] path = the/path/to/Code.exe cmd = \"Code.exe\" --wait --merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\" Without the mergetool.cmd configuration and an unsupported merge.tool entry, git gui behaves mainly as before this change and informs the user about an unsupported merge tool. In addtition it also shows a hint to add a config entry to use the tool as an unsupported tool with degraded support. If a wrong mergetool.cmd is configured by accident, it gets handled by git gui already. In this case git gui informs the user that the merge tool couldn't be opened. This behavior is preserved by this change and should not change. "Beyond Compare 3" and "Visual Studio Code" were tested as manually configured merge tools. Signed-off-by: Tobias Boesch --- git-gui/lib/mergetool.tcl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/git-gui/lib/mergetool.tcl b/git-gui/lib/mergetool.tcl index e688b016ef6c9d..4fabf26b8db1bd 100644 --- a/git-gui/lib/mergetool.tcl +++ b/git-gui/lib/mergetool.tcl @@ -272,8 +272,24 @@ proc merge_resolve_tool2 {} { } } default { - error_popup [mc "Unsupported merge tool '%s'" $tool] - return + set tool_cmd [get_config mergetool.$tool.cmd] + if {$tool_cmd ne {}} { + foreach command_part $tool_cmd { + if {([string first {[} $tool_cmd] != -1) || ([string first {]} $tool_cmd] != -1)} { + error_popup [mc "Unable to process square brackets in mergetool.cmd configuration option.\ + Please remove the square brackets."] + return + } else { + lappend cmdline [subst -nobackslashes -nocommands $command_part] + } + } + } else { + error_popup [mc "Unsupported merge tool '%s'.\n + Currently unsupported tools can be added and used as unsupported tools with degraded support\ + by adding the command of the tool to the \"mergetool.cmd\" option in the config. + See the configuration documentation for more details." $tool] + return + } } }