Skip to content

Commit 8ff65c7

Browse files
ToBoMij6t
authored andcommitted
git gui: add directly calling merge tool from configuration
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 configuration. 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 configuration while git Gui doesn't. With this change git gui can call merge tools configured in the configuration directly without a change in git gui source code. It needs a configured "merge.tool" and a configured "mergetool.<mergetool name>.cmd" configuration entry as shown in the git-config manual page. Configuration example: [merge] tool = vscode [mergetool "vscode"] cmd = \"the/path/to/Code.exe\" --wait --merge \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\" Without the "mergetool.<mergetool name>.cmd" entry 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 configuration entry to use the tool as an unsupported tool with degraded support. If a wrong "mergetool.<mergetool name>.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 <[email protected]> Signed-off-by: Johannes Sixt <[email protected]>
1 parent 2864e85 commit 8ff65c7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/mergetool.tcl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,25 @@ proc merge_resolve_tool2 {} {
272272
}
273273
}
274274
default {
275-
error_popup [mc "Unsupported merge tool '%s'" $tool]
276-
return
275+
set tool_cmd [get_config mergetool.$tool.cmd]
276+
if {$tool_cmd ne {}} {
277+
if {([string first {[} $tool_cmd] != -1) || ([string first {]} $tool_cmd] != -1)} {
278+
error_popup [mc "Unable to process square brackets in \"mergetool.%s.cmd\" configuration option.
279+
280+
Please remove the square brackets." $tool]
281+
return
282+
} else {
283+
set cmdline {}
284+
foreach command_part $tool_cmd {
285+
lappend cmdline [subst -nobackslashes -nocommands $command_part]
286+
}
287+
}
288+
} else {
289+
error_popup [mc "Unsupported merge tool '%s'.
290+
291+
To use this tool, configure \"mergetool.%s.cmd\" as shown in the git-config manual page." $tool $tool]
292+
return
293+
}
277294
}
278295
}
279296

0 commit comments

Comments
 (0)