From: "ToBoMi via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Sixt <j6t@kdbg.org>, ToBoMi <tobias.boesch@miele.com>,
Tobias Boesch <tobias.boesch@miele.com>
Subject: [PATCH v3] git gui: add directly calling merge tool from gitconfig
Date: Fri, 06 Sep 2024 07:27:23 +0000 [thread overview]
Message-ID: <pull.1773.v3.git.1725607643479.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1773.v2.git.1724833917245.gitgitgadget@gmail.com>
From: Tobias Boesch <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. 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 <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
Changes since v2:
* Changed commit ident
* Added hint to add a mergetool as an unsupprted tool
* Minor typos
* Highlighted proper nouns in commit message
* Only using mergetool.cmd now - not using mergetool.path anymore
* Removed gitconfig term in user message
* Changed lines length of commit message
* tcl commands in mergetool.cmd are now detected and not executed
anymore
* mergetool.cmd string parts are now substituted as list, not as a
whole string
* Made a more clear user hint on how to configure an unsupported
mergetool
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1773%2FToBoMi%2Fadd_merge_tool_from_config_file-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1773/ToBoMi/add_merge_tool_from_config_file-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1773
Range-diff vs v2:
1: e77d6dec6c5 ! 1: c8c0107ddc5 git gui: add directly calling merge tool from gitconfig
@@
## Metadata ##
-Author: deboeto <tobias.boesch@miele.com>
+Author: Tobias Boesch <tobias.boesch@miele.com>
## Commit message ##
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.
+ 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).
+ 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.
+ 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.
+ 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.
+ 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]
@@ Commit message
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.
+ 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 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.
+ 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.
+ "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: proc merge_resolve_tool2 {} {
- 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]
++ 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 {
++ foreach command_part $tool_cmd {
++ lappend cmdline [subst -nobackslashes -nocommands $command_part]
++ }
++ }
+ } else {
-+ error_popup [mc "Unsupported merge tool '%s'. Is the tool command and path configured properly in gitconfig?" $tool]
++ 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
+ }
}
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 e688b016ef6..ccbc1a46554 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 {}} {
+ 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 {
+ foreach command_part $tool_cmd {
+ 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
+ }
}
}
base-commit: 2e7b89e038c0c888acf61f1b4ee5a43d4dd5e94c
--
gitgitgadget
next prev parent reply other threads:[~2024-09-06 7:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-19 11:29 [PATCH] git gui: add directly calling merge tool from gitconfig ToBoMi via GitGitGadget
2024-08-24 13:38 ` Johannes Sixt
2024-08-27 12:51 ` AW: " tobias.boesch
2024-08-27 13:53 ` tobias.boesch
2024-08-28 8:31 ` [PATCH v2] " ToBoMi via GitGitGadget
2024-08-28 17:08 ` Junio C Hamano
2024-09-05 8:09 ` AW: " tobias.boesch
2024-08-31 13:51 ` Johannes Sixt
2024-09-06 6:32 ` AW: " tobias.boesch
2024-09-06 17:43 ` Johannes Sixt
2024-09-06 7:27 ` ToBoMi via GitGitGadget [this message]
2024-09-08 12:21 ` [PATCH v3] " Johannes Sixt
2024-09-11 13:41 ` AW: " tobias.boesch
2024-09-11 14:23 ` [PATCH v4] git gui: add directly calling merge tool from configuration ToBoMi via GitGitGadget
2024-09-12 10:17 ` [PATCH v5] " ToBoMi via GitGitGadget
2024-09-14 13:32 ` Johannes Sixt
2024-09-16 8:42 ` AW: " tobias.boesch
2024-11-07 14:16 ` tobias.boesch
2024-11-07 16:43 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1773.v3.git.1725607643479.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=tobias.boesch@miele.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).