path: root/
AgeCommit message (Collapse)Author
2019-05-19Merge branch 'dl/difftool-mergetool'Junio C Hamano
Update "git difftool" and "git mergetool" so that the combinations of {diff,merge}.{tool,guitool} configuration variables serve as fallback settings of each other in a sensible order. * dl/difftool-mergetool: difftool: fallback on merge.guitool difftool: make --gui, --tool and --extcmd mutually exclusive mergetool: fallback to tool when guitool unavailable mergetool--lib: create gui_mode function mergetool: use get_merge_tool function t7610: add mergetool --gui tests t7610: unsuppress output
2019-05-13mergetool: fallback to tool when guitool unavailableDenton Liu
In git-difftool, if the tool is called with --gui but `diff.guitool` is not set, it falls back to `diff.tool`. Make git-mergetool also fallback from `merge.guitool` to `merge.tool` if the former is undefined. If git-difftool, when called with `--gui`, were to use `get_configured_mergetool` in a future patch, it would also get the fallback behavior in the following precedence: 1. diff.guitool 2. merge.guitool 3. diff.tool 4. merge.tool The behavior for when difftool or mergetool are called without `--gui` should be identical with or without this patch. Note that the search loop could be written as sections="merge" keys="tool" if diff_mode then sections="diff $sections" fi if gui_mode then keys="guitool $keys" fi merge_tool=$( IFS=' ' for key in $keys do for section in $sections do selected=$(git config $section.$key) if test -n "$selected" then echo "$selected" return fi done done) which would make adding a mode in the future much easier. However, adding a new mode will likely never happen as it is highly discouraged so, as a result, it is written in its current form so that it is more readable for future readers. Signed-off-by: Denton Liu <> Signed-off-by: Junio C Hamano <>
2019-05-13mergetool--lib: create gui_mode functionDenton Liu
Before, in `get_configured_merge_tool`, we would test the value of the first argument directly, which corresponded to whether we were using guitool. However, since `$GIT_MERGETOOL_GUI` is available as an environment variable, create the `gui_mode` function which increases the clarify of functions which use it. While we're at it, add a space before `()` in function definitions to fix the style. Signed-off-by: Denton Liu <> Signed-off-by: Junio C Hamano <>
2019-05-13mergetool: use get_merge_tool functionDenton Liu
In git-mergetool, the logic for getting which merge tool to use is duplicated in git-mergetool--lib, except for the fact that it needs to know whether the tool was guessed or not. Rewrite `get_merge_tool` to return whether or not the tool was guessed through the return code and make git-mergetool call this function instead of duplicating the logic. Note that 1 was chosen to be the return code of when a tool is guessed because it seems like a slightly more abnormal condition than getting a tool that's explicitly specified but this is completely arbitrary. Also, let `$GIT_MERGETOOL_GUI` be set to determine whether or not the guitool will be selected. This change is not completely backwards compatible as there may be external users of git-mergetool--lib. However, only one user, git-diffall[1], was found from searching GitHub and Google, and this tool is superseded by `git difftool --dir-diff` anyway. It seems very unlikely that there exists an external caller that would take into account the return code of `get_merge_tool` as it would always return 0 before this change so this change probably does not affect any external users. [1]: Signed-off-by: Denton Liu <> Signed-off-by: Junio C Hamano <>
2019-04-04mergetools: add support for smerge (Sublime Merge)David Aguilar
Teach difftool and mergetool about the Sublime Merge "smerge" command. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2018-10-25mergetool: accept -g/--[no-]gui as argumentsDenton Liu
In line with how difftool accepts a -g/--[no-]gui option, make mergetool accept the same option in order to use the `merge.guitool` variable to find the default mergetool instead of `merge.tool`. Signed-off-by: Denton Liu <> Signed-off-by: Anmol Mago <> Signed-off-by: Brian Ho <> Signed-off-by: David Lu <> Signed-off-by: Ryan Wang <> Acked-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2016-11-29mergetool: honor mergetool.$tool.trustExitCode for built-in toolsDavid Aguilar
Built-in merge tools contain a hard-coded assumption about whether or not a tool's exit code can be trusted to determine the success or failure of a merge. Tools whose exit codes are not trusted contain calls to check_unchanged() in their merge_cmd() functions. A problem with this is that the trustExitCode configuration is not honored for built-in tools. Teach built-in tools to honor the trustExitCode configuration. Extend run_merge_cmd() so that it is responsible for calling check_unchanged() when a tool's exit code cannot be trusted. Remove check_unchanged() calls from scriptlets since they are no longer responsible for calling it. When no configuration is present, exit_code_trustable() is checked to see whether the exit code should be trusted. The default implementation returns false. Tools whose exit codes can be trusted override exit_code_trustable() to true. Reported-by: Dun Peal <> Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2016-05-03Merge branch 'nf/mergetool-prompt'Junio C Hamano
UI consistency improvements. * nf/mergetool-prompt: difftool/mergetool: make the form of yes/no questions consistent
2016-04-25difftool/mergetool: make the form of yes/no questions consistentNikola Forró
Every yes/no question in difftool/mergetool scripts has slightly different form, and none of them is consistent with the form git itself uses. Make the form of all the questions consistent with the form used by git. Reviewed-by: John Keeping <> Signed-off-by: Nikola Forró <> Acked-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2016-04-04mergetools: create mergetool_find_win32_cmd() helper function for winmergeJacob Nisnevich
Signed-off-by: Jacob Nisnevich <> Acked-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2015-06-19mergetool-lib: fix default tool selectionMichael J Gruber
When no diff nor merge tool is specified (config, option), mergetool-lib is supposed to choose a default tool from a set of tools. That set is constructed dynamically depending on the environment (graphical, editor setting) as a space separated string of tool names. 719518f (mergetool--lib: set IFS for difftool and mergetool, 2015-05-20) introduced a newline as IFS which breaks the parsing of the space separated list into items, resulting in a failed search for an available tool. Set IFS to a space locally for the tool search. Signed-off-by: Michael J Gruber <> Signed-off-by: Junio C Hamano <>
2015-05-20mergetool--lib: set IFS for difftool and mergetoolDavid Aguilar
git-sh-setup sets IFS but it is not used by git-difftool--helper. Set IFS in git-mergetool--lib so that the mergetool scriptlets, difftool, and mergetool do not need to do so. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2014-11-21mergetool--lib: remove use of $status globalDavid Aguilar
Remove return statements and rework check_unchanged() so that the exit status from the last evaluated expression bubbles up to the callers. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2014-11-21mergetool--lib: remove no-op assignment to $status from setup_user_toolJunio C Hamano
Even though setup_user_tool assigns the exit status from "eval $merge_tool_cmd" to $status, the variable is overwritten by the function it calls next, check_unchanged, without ever getting looked at by anybody. And "return $status" at the end of this function returns the value check_unchanged assigned to it (which is the same as the value the function returns). Which makes the assignment a no-op. Remove it. Signed-off-by: Junio C Hamano <>
2014-11-18Merge branch 'da/difftool'Junio C Hamano
Fix-up to a new feature in 'master'. * da/difftool: difftool: honor --trust-exit-code for builtin tools
2014-11-14difftool: honor --trust-exit-code for builtin toolsDavid Aguilar
run_merge_tool() was not setting $status, which prevented the exit code for builtin tools from being forwarded to the caller. Capture the exit status and add a test to guarantee the behavior. Reported-by: Adria Farres <> Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2014-10-21mergetool: rename bc3 to bcJunio C Hamano
Beyond Compare version 4 works the same way as version 3, so rename the existing "bc3" adaptor to just "bc", while keeping "bc3" as a backward compatible wrapper. Noticed-by: Olivier Croquette <> Helped-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-11-26remove #!interpreter line from shell librariesJonathan Nieder
In a shell snippet meant to be sourced by other shell scripts, an opening #! line does more harm than good. The harm: - When the shell library is sourced, the interpreter and options from the #! line are not used. Specifying a particular shell can confuse the reader into thinking it is safe for the shell library to rely on idiosyncrasies of that shell. - Using #! instead of a plain comment drops a helpful visual clue that this is a shell library and not a self-contained script. - Tools such as lintian can use a #! line to tell when an installation script has failed by forgetting to set a script executable. This check does not work if shell libraries also start with a #! line. The good: - Text editors notice the #! line and use it for syntax highlighting if you try to edit the installed scripts (without ".sh" suffix) in place. The use of the #! for file type detection is not needed because Git's shell libraries are meant to be edited in source form (with ".sh" suffix). Replace the opening #! lines with comments. This involves tweaking the test harness's valgrind support to find shell libraries by looking for "# " in the first line instead of "#!" (see v1.7.6-rc3~7, 2011-06-17). Suggested by Russ Allbery through lintian. Thanks to Jeff King and Clemens Buchacher for further analysis. Tested by searching for non-executable scripts with #! line: find . -name .git -prune -o -type f -not -executable | while read file do read line <"$file" case $line in '#!'*) echo "$file" ;; esac done The only remaining scripts found are templates for shell scripts (, and sample input used in tests (t/t4034/perl/{pre,post}). Signed-off-by: Jonathan Nieder <> Signed-off-by: Junio C Hamano <>
2013-10-14mergetool--lib: Fix typo in the merge/difftool helpStefan Saasen
The help text for the `tool` flag should mention: --tool=<tool> instead of: --tool-<tool> Signed-off-by: Stefan Saasen <> Reviewed-by: David Aguilar <> Signed-off-by: Jonathan Nieder <>
2013-10-13mergetools/diffmerge: support DiffMerge as a git mergetoolStefan Saasen
DiffMerge is a non-free (but gratis) tool that supports OS X, Windows and Linux. See DiffMerge includes a script `/usr/bin/diffmerge` that can be used to launch the graphical compare tool. This change adds mergetool support for DiffMerge and adds 'diffmerge' as an option to the mergetool help. Signed-off-by: Stefan Saasen <> Acked-by: David Aguilar <> Signed-off-by: Jonathan Nieder <>
2013-07-29many small typofixesOndřej Bílka
Signed-off-by: Ondřej Bílka <> Reviewed-by: Marc Branchaud <> Signed-off-by: Junio C Hamano <>
2013-06-17mergetool--lib: refactor {diff,merge}_cmd logicJohn Keeping
Instead of needing a wrapper to call the diff/merge command, simply provide the diff_cmd and merge_cmd functions for user-specified tools in the same way as we do for built-in tools. Signed-off-by: John Keeping <> Acked-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-02-03doc: generate a list of valid merge toolsDavid Aguilar
Use the show_tool_names() function to build lists of all the built-in tools supported by difftool and mergetool. This frees us from needing to update the documentation whenever a new tool is added. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-02-03mergetool--lib: list user configured tools in '--tool-help'John Keeping
Signed-off-by: John Keeping <> Signed-off-by: Junio C Hamano <>
2013-02-03mergetool--lib: add functions for finding available toolsDavid Aguilar
Refactor show_tool_help() so that the tool-finding logic is broken out into a separate show_tool_names() function. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-29mergetool--lib: improve the help text in guess_merge_tool()David Aguilar
This code path is only activated when the user does not have a valid configured tool. Add a message to guide new users towards configuring a default tool. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-29mergetool--lib: simplify command expressionsDavid Aguilar
Update variable assignments to always use $(command "$arg") in their RHS instead of "$(command "$arg")" as the latter is harder to read. Make get_merge_tool_cmd() simpler by avoiding "echo" and $(command) substitutions completely. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-29mergetools: simplify how we handle "vim" and "defaults"David Aguilar
Remove the exceptions for "vim" and "defaults" in the mergetool library so that every filename in mergetools/ matches 1:1 with the name of a valid built-in tool. Define the trivial fallback definition of shell functions in-line in git-mergetool-lib script, instead of dot-sourcing them from another file. The result is much easier to follow. [jc: squashed in an update from John Keeping as well] Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-28mergetool--lib: don't call "exit" in setup_toolJohn Keeping
This will make it easier to use setup_tool in places where we expect that the selected tool will not support the current mode. We need to introduce a new return code for setup_tool to differentiate between the case of "the selected tool is invalid" and "the selected tool is not a built-in" since we must call setup_tool when a custom 'merge.<tool>.path' is configured for a built-in tool but avoid failing when the configured tool is not a built-in. Signed-off-by: John Keeping <> Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-28mergetool--lib: improve show_tool_help() outputDavid Aguilar
Check the can_diff and can_merge functions before deciding whether to add the tool to the available/unavailable lists. This makes "--tool-help" context-sensitive so that "git mergetool --tool-help" displays merge tools only and "git difftool --tool-help" displays diff tools only. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-25git-mergetool: don't hardcode 'mergetool' in show_tool_helpJohn Keeping
When using show_tool_help from git-difftool we will want it to print "git difftool" not "git mergetool" so use "git ${TOOL_MODE}tool". Signed-off-by: John Keeping <> Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-25git-mergetool: remove redundant assignmentJohn Keeping
TOOL_MODE is set at the top of so there is no need to set it again in show_tool_help. Removing this lets us re-use show_tool_help in git-difftool. Signed-off-by: John Keeping <> Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2013-01-25git-mergetool: move show_tool_help to mergetool--libJohn Keeping
This is the first step in unifying "git difftool --tool-help" and "git mergetool --tool-help". Signed-off-by: John Keeping <> Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2012-10-01Merge branch 'da/mergetool-custom'Junio C Hamano
The actual external command to run for mergetool backend can be specified with difftool/mergetool.$name.cmd configuration variables, but this mechanism was ignored for the backends we natively support. * da/mergetool-custom: mergetool--lib: Allow custom commands to override built-ins
2012-09-25mergetool--lib: Allow custom commands to override built-insDavid Aguilar
Allow users to override the default commands provided by the mergetools/* scriptlets. Users occasionally run into problems where they expect to be able to override the built-in tool names. The documentation does not explicitly mention that built-ins cannot be overridden, so it's easy to assume that it should work. Lift this restriction so that built-in tools are handled the same way as user-configured tools. Add tests to guarantee this behavior. A nice benefit of this change is that it protects users from having future versions of git trump their custom configuration with a new built-in tool. C.f.: Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2012-08-27Merge branch 'da/difftool-updates'Junio C Hamano
"git difftool --dir-diff" learned to use symbolic links to prepare temporary copy of the working tree when available. * da/difftool-updates: difftool: silence warning Add Code Compare v2.80.4 as a merge / diff tool for Windows mergetool,difftool: Document --tool-help consistently difftool: Disable --symlinks on cygwin difftool: Handle compare() returning -1 difftool: Wrap long lines for readability difftool: Check all return codes from compare() difftool: Handle finding mergetools/ in a path with spaces difftool: Use symlinks when diffing against the worktree difftool: Call the temp directory "git-difftool" difftool: Move option values into a hash difftool: Eliminate global variables difftool: Simplify print_tool_help()
2012-08-10Add Code Compare v2.80.4 as a merge / diff tool for WindowsSebastian Schuberth
Code Compare is a commercial file comparison tool for Windows, see Version 2.80.4 added support for command line arguments preceded by a dash instead of a slash. This is required for Git for Windows because slashes in command line arguments get mangled with according to these rules: Signed-off-by: Sebastian Schuberth <> Signed-off-by: Junio C Hamano <>
2012-07-23mergetool: support --tool-help option like difftool doesJunio C Hamano
This way we do not have to risk the list of tools going out of sync between the implementation and the documentation. In the same spirit as bf73fc2 (difftool: print list of valid tools with '--tool-help', 2012-03-29), trim the list of merge backends in the documentation. We do not want to have a complete list of valid tools; we only want a list to help people guess what kind of things the tools do to be specified there, and refer them to --tool-help for a complete list. Signed-off-by: Junio C Hamano <>
2011-09-20Merge branch 'maint'Junio C Hamano
* maint: git-mergetool: check return value from read
2011-09-20git-mergetool: check return value from readJay Soffian
Mostly fixed already by 6b44577 (mergetool: check return value from read, 2011-07-01). Catch two uses it missed. Signed-off-by: Jay Soffian <> Signed-off-by: Junio C Hamano <>
2011-08-19mergetool--lib: Refactor tools into separate filesDavid Aguilar
Individual merge tools are now defined in a mergetools/$tool file which is sourced at runtime. The individual files are installed into $(git --exec-path)/mergetools/. New tools can be added by creating a new file instead of editing the scriptlet. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2011-08-19mergetool--lib: Make style consistent with gitDavid Aguilar
Use the predominant conditional style where "then" appears alone on the line after the test expression. Remove spaces after ">" output redirections. Remove unnecessary parentheses around the kdiff3 commands. Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
2011-08-05misc-sh: fix up whitespace in some other .sh files.Jon Seymour
I found that the patched 4 files were different when this filter is applied. expand -i | unexpand --first-only This patch contains the corrected files. Signed-off-by: Jon Seymour <> Signed-off-by: Junio C Hamano <>
2011-06-30Merge branch 'da/git-prefix-everywhere' into nextJunio C Hamano
* da/git-prefix-everywhere: t/ Add GIT_PREFIX tests git-mergetool--lib: Make vimdiff retain the current directory git: Remove handling for GIT_PREFIX setup: Provide GIT_PREFIX to built-ins
2011-05-26git-mergetool--lib: Make vimdiff retain the current directoryDavid Aguilar
When using difftool with vimdiff it can be unexpected that the current directory changes to the root of the project. Tell vim to chdir to the value of $GIT_PREFIX to fix this. Care is taken to quote the variable so that vim expands it. This avoids problems when directory names contain spaces. Signed-off-by: David Aguilar <> Reported-by: Frédéric Heitzmann <> Signed-off-by: Junio C Hamano <>
2011-05-01Pass empty file to p4merge where no base is suitable.Ciaran Jessup
Modify the p4merge client command to pass a reference to an empty file instead of the local file when no base revision available. In the situation where a merge tries to add a file from one branch into a branch that already contains that file (by name), p4merge currently seems to have successfully automatically resolved the 'conflict' when it is opened (correctly if the files differed by just whitespace for example) but leaves the save button disabled. This means the user of the p4merge client cannot commit the resolved changes back to disk and merely exits, leaving the original (merge-conflicted) file intact on the disk. Provide an empty base file to p4merge so that it leaves the save button enabled. This will allow saving of the auto-resolution to disk. Signed-off-by: Ciaran Jessup <> Signed-off-by: Junio C Hamano <>
2011-03-20Merge branch 'ss/mergetool--lib'Junio C Hamano
* ss/mergetool--lib: mergetool--lib: Add Beyond Compare 3 as a tool mergetool--lib: Sort tools alphabetically for easier lookup
2011-02-28mergetool--lib: Add Beyond Compare 3 as a toolSebastian Schuberth
Signed-off-by: Sebastian Schuberth <> Tested-by: Chris Packham <> Signed-off-by: Junio C Hamano <>
2011-02-28mergetool--lib: Sort tools alphabetically for easier lookupSebastian Schuberth
Signed-off-by: Sebastian Schuberth <> Tested-by: Chris Packham <> Signed-off-by: Junio C Hamano <>
2011-02-25mergetool-lib: call vim in readonly mode for diffsMichael J Gruber
When [g]vimdiff is called for files which are opened already, the editor complains about the existing swap file. But we do not want to write anything when called from difftool. So, make difftool use "-R" for the vim family. This - prevents the use of a swap file and - marks the buffers readonly. Signed-off-by: Michael J Gruber <> Signed-off-by: Junio C Hamano <>