Skip to content

Commit

Permalink
git gui: add directly calling merge tool from gitconfig
Browse files Browse the repository at this point in the history
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, but now also
shows a hint to add a config entry for the tool
in gitconfig.

If a wrong mergetool.cmd is configured by accident
it is beeing 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]>
  • Loading branch information
ToBoMi committed Aug 27, 2024
1 parent 159f2d5 commit e77d6de
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions git-gui/lib/mergetool.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,14 @@ 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 {}} {
set tool_cmd_file_vars_resolved [subst -nobackslashes -nocommands $tool_cmd]
set cmdline [lreplace $tool_cmd_file_vars_resolved 0 0 $merge_tool_path]
} else {
error_popup [mc "Unsupported merge tool '%s'. Is the tool command and path configured properly in gitconfig?" $tool]
return
}
}
}

Expand Down

0 comments on commit e77d6de

Please sign in to comment.