git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] git gui: add directly calling merge tool from gitconfig

From
TGToBoMi via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 28, 2024, 08:31 UTC
Message-ID
<pull.1773.v2.git.1724833917245.gitgitgadget@gmail.com>
In-Reply-To
<pull.1773.git.1724066944786.gitgitgadget@gmail.com>
From: deboeto <tobias.boesch@miele.com>

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 <tobias.boesch@miele.com>
---
    git gui: add directly calling merge tool from gitconfig
    
    cc: Johannes Sixt j6t@kdbg.org
    
    Changes since v1:
    
     * Used existing option mergetool.cmd in gitconfig to trigger the direct
       call of the merge tool configured in the config instead adding a new
       option mergeToolFromConfig
     * Removed assignment of merge tool path to a variable and reused the
       already existing one: merget_tool_path
     * Changed formatting of the commit message
     * Added more context and an examples to the commit message
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1773%2FToBoMi%2Fadd_merge_tool_from_config_file-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1773/ToBoMi/add_merge_tool_from_config_file-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1773
Range-diff vs v1:
 1:  59e8f454a70 ! 1:  e77d6dec6c5 git gui: add directly calling merge tool from gitconfig
     @@ Metadata
       ## Commit message ##
          git gui: add directly calling merge tool from gitconfig
      
     -    * git Gui can open a merge tool when conflicts are
     -        detected. The merge tools that are allowed to
     -        call have to be hard coded into git Gui
     -        althgough there are configuration options for
     -        merge tools git in the git config. Git calls
     -        the configured merge tools directly from the
     -        config while git Gui doesn't.
     -    * git Gui can now call the tool configured in the
     -        gitconfig directly.
     -    * Can be enabled through setting
     -        gui.mergeToolFromConfig
     -    * Disabled by default, since option is most likely
     -        never set
     -    * bc3 and vscode tested
     -
     -    Signed-off-by: deboeto <tobias.boesch@miele.com>
     -
     - ## Documentation/config/gui.txt ##
     -@@ Documentation/config/gui.txt: gui.blamehistoryctx::
     - 	linkgit:gitk[1] for the selected commit, when the `Show History
     - 	Context` menu item is invoked from 'git gui blame'. If this
     - 	variable is set to zero, the whole history is shown.
     -+
     -+gui.mergeToolFromConfig::
     -+	If true, allow to call the merge tool configured in gitconfig
     -+	in git gui directly.
     - \ No newline at end of file
     +    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 <tobias.boesch@miele.com>
      
       ## git-gui/lib/mergetool.tcl ##
      @@ git-gui/lib/mergetool.tcl: proc merge_resolve_tool2 {} {
     @@ git-gui/lib/mergetool.tcl: proc merge_resolve_tool2 {} {
       	default {
      -		error_popup [mc "Unsupported merge tool '%s'" $tool]
      -		return
     -+		if {[is_config_true gui.mergetoolfromconfig]} {
     -+			set path [get_config mergetool.$tool.path]
     -+			set cmdline_config [get_config mergetool.$tool.cmd]
     -+			set cmdline_substituted [subst -nobackslashes -nocommands $cmdline_config]
     -+			set cmdline [lreplace $cmdline_substituted 0 0 $path]
     ++		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'" $tool]
     ++			error_popup [mc "Unsupported merge tool '%s'. Is the tool command and path configured properly in gitconfig?" $tool]
      +			return
      +		}
       	}
 git-gui/lib/mergetool.tcl | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/git-gui/lib/mergetool.tcl b/git-gui/lib/mergetool.tcl
index e688b016ef6..4c4e8f47bb0 100644
--- a/git-gui/lib/mergetool.tcl
+++ b/git-gui/lib/mergetool.tcl
@@ -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
+		}
 	}
 	}
 

base-commit: 159f2d50e75c17382c9f4eb7cbda671a6fa612d1
-- 
gitgitgadget
Previous: tobias.boesch@miele.comNext: Junio C Hamano
Message 5 of 19 in “git gui: add directly calling merge tool from gitconfig”
  1. git gui: add directly calling merge tool from gitconfigToBoMi via GitGitGadget, Aug 19, 2024
  2. Johannes SixtAug 24, 2024
  3. AW: [PATCH] git gui: add directly calling merge tool from gitconfigtobias.boesch@miele.com, Aug 27, 2024
  4. AW: [PATCH] git gui: add directly calling merge tool from gitconfigtobias.boesch@miele.com, Aug 27, 2024
  5. git gui: add directly calling merge tool from gitconfigToBoMi via GitGitGadget, Aug 28, 2024
  6. Junio C HamanoAug 28, 2024
  7. AW: [PATCH v2] git gui: add directly calling merge tool from gitconfigtobias.boesch@miele.com, Sep 5, 2024
  8. Johannes SixtAug 31, 2024
  9. AW: [PATCH v2] git gui: add directly calling merge tool from gitconfigtobias.boesch@miele.com, Sep 6, 2024
  10. Johannes SixtSep 6, 2024
  11. git gui: add directly calling merge tool from gitconfigToBoMi via GitGitGadget, Sep 6, 2024
  12. Johannes SixtSep 8, 2024
  13. AW: [PATCH v3] git gui: add directly calling merge tool from gitconfigtobias.boesch@miele.com, Sep 11, 2024
  14. git gui: add directly calling merge tool from configurationToBoMi via GitGitGadget, Sep 11, 2024
  15. git gui: add directly calling merge tool from configurationToBoMi via GitGitGadget, Sep 12, 2024
  16. Johannes SixtSep 14, 2024
  17. AW: [PATCH v5] git gui: add directly calling merge tool from configurationtobias.boesch@miele.com, Sep 16, 2024
  18. AW: [PATCH v5] git gui: add directly calling merge tool from configurationtobias.boesch@miele.com, Nov 7, 2024
  19. Johannes SixtNov 7, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.