aboutsummaryrefslogtreecommitdiffstats
path: root/git-mergetool.sh
AgeCommit message (Collapse)AuthorFilesLines
2023-04-05mergetool: new config guiDefault supports auto-toggling gui by DISPLAYTao Klerks1-2/+7
When no merge.tool or diff.tool is configured or manually selected, the selection of a default tool is sensitive to the DISPLAY variable; in a GUI session a gui-specific tool will be proposed if found, and otherwise a terminal-based one. This "GUI-optimizing" behavior is important because a GUI can make a huge difference to a user's ability to understand and correctly complete a non-trivial conflicting merge. Some time ago the merge.guitool and diff.guitool config options were introduced to enable users to configure both a GUI tool, and a non-GUI tool (with fallback if no GUI tool configured), in the same environment. Unfortunately, the --gui argument introduced to support the selection of the guitool is still explicit. When using configured tools, there is no equivalent of the no-tool-configured "propose a GUI tool if we are in a GUI environment" behavior. As proposed in <xmqqmtb8jsej.fsf@gitster.g>, introduce new configuration options, difftool.guiDefault and mergetool.guiDefault, supporting a special value "auto" which causes the corresponding tool or guitool to be selected depending on the presence of a non-empty DISPLAY value. Also support "true" to say "default to the guitool (unless --no-gui is passed on the commandline)", and "false" as the previous default behavior when these new configuration options are not specified. Signed-off-by: Tao Klerks <tao@klerks.biz> Acked-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-13mergetool: do not enable hideResolved by defaultJonathan Nieder1-7/+2
When 98ea309b3f (mergetool: add hideResolved configuration, 2021-02-09) introduced the mergetool.hideResolved setting to reduce the clutter in viewing non-conflicted sections of files in a mergetool, it enabled it by default, explaining: No adverse effects were noted in a small survey of popular mergetools[1] so this behavior defaults to `true`. In practice, alas, adverse effects do appear. A few issues: 1. No indication is shown in the UI that the base, local, and remote versions shown have been modified by additional resolution. This is inherent in the design: the idea of mergetool.hideResolved is to convince a mergetool that expects pristine local, base, and remote files to show partially resolved verisons of those files instead; there is no additional source of information accessible to the mergetool to see where the resolution has happened. (By contrast, a mergetool generating the partial resolution from conflict markers for itself would be able to hilight the resolved sections with a different color.) A user accustomed to seeing the files without partial resolution gets no indication that this behavior has changed when they upgrade Git. 2. If the computed merge did not line up the files correctly (for example due to repeated sections in the file), the partially resolved files can be misleading and do not have enough information to reconstruct what happened and compute the correct merge result. 3. Resolving a conflict can involve information beyond the textual conflict. For example, if the local and remote versions added overlapping functionality in different ways, seeing the full unresolved versions of each alongside the base gives information about each side's intent that makes it possible to come up with a resolution that combines those two intents. By contrast, when starting with partially resolved versions of those files, one can produce a subtly wrong resolution that includes redundant extra code added by one side that is not needed in the approach taken on the other. All that said, a user wanting to focus on textual conflicts with reduced clutter can still benefit from mergetool.hideResolved=true as a way to deemphasize sections of the code that resolve cleanly without requiring any changes to the invoked mergetool. The caveats described above are reduced when the user has explicitly turned this on, because then the user is aware of them. Flip the default to 'false'. Reported-by: Dana Dahlstrom <dahlstrom@google.com> Helped-by: Seth House <seth@eseth.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-02-09mergetool: add per-tool support and overrides for the hideResolved flagSeth House1-1/+35
Add a per-tool override flag so that users may enable the flag for one tool and disable it for another by setting `mergetool.<tool>.hideResolved` to `false`. In addition, the author or maintainer of a mergetool may optionally override the default `hideResolved` value for that mergetool. If the `mergetools/<tool>` shell script contains a `hide_resolved_enabled` function it will be called when the mergetool is invoked and the return value will be used as the default for the `hideResolved` flag. hide_resolved_enabled () { return 1 } Disabling may be desirable if the mergetool wants or needs access to the original, unmodified 'LOCAL' and 'REMOTE' versions of the conflicted file. For example: - A tool may use a custom conflict resolution algorithm and prefer to ignore the results of Git's conflict resolution. - A tool may want to visually compare/constrast the version of the file from before the merge (saved to 'LOCAL', 'REMOTE', and 'BASE') with Git's conflict resolution results (saved to 'MERGED'). Helped-by: Johannes Sixt <j6t@kdbg.org> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Seth House <seth@eseth.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-02-09mergetool: break setup_tool out into separate initialization functionSeth House1-0/+2
This is preparation for the following commit where we need to source the mergetool shell script to look for overrides before `run_merge_tool` is called. Previously `run_merge_tool` both sourced that script and invoked the mergetool. In the case of the following commit, we need the result of the `hide_resolved` override, if present, before we actually run `run_merge_tool`. The new `initialize_merge_tool` wrapper is exposed and documented as a public interface for consistency with the existing `run_merge_tool` which is also public. Although `setup_tool` could instead be exposed directly, the related `setup_user_tool` would probably also want to be elevated to match and this felt the cleanest to me. Signed-off-by: Seth House <seth@eseth.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-02-09mergetool: add hideResolved configurationSeth House1-0/+14
The purpose of a mergetool is to help the user resolve any conflicts that Git cannot automatically resolve. If there is a conflict that must be resolved manually Git will write a file named MERGED which contains everything Git was able to resolve by itself and also everything that it was not able to resolve wrapped in conflict markers. One way to think of MERGED is as a two- or three-way diff. If each "side" of the conflict markers is separately extracted an external tool can represent those conflicts as a side-by-side diff. However many mergetools instead diff LOCAL and REMOTE both of which contain versions of the file from before the merge. Since the conflicts Git resolved automatically are not present it forces the user to manually re-resolve those conflicts. Some mergetools also show MERGED but often only for reference and not as the focal point to resolve the conflicts. This adds a `mergetool.hideResolved` flag that will overwrite LOCAL and REMOTE with each corresponding "side" of a conflicted file and thus hide all conflicts that Git was able to resolve itself. Overwriting these files will immediately benefit any mergetool that uses them without requiring any changes to the tool. No adverse effects were noted in a small survey of popular mergetools[1] so this behavior defaults to `true`. However it can be globally disabled by setting `mergetool.hideResolved` to `false`. [1] https://www.eseth.org/2020/mergetools.html https://github.com/whiteinge/eseth/blob/c884424769fffb05d87afb33b2cf80cecb4044c3/2020/mergetools.md Original-implementation-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Seth House <seth@eseth.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-06-12mergetool: use shell variable magic instead of `awk`Johannes Sixt1-5/+20
git-mergetool spawns an enormous amount of processes. For this reason, the test script, t7610, is exceptionally slow, in particular, on Windows. Most of the processes are invocations of git. There are also some that can be replaced with shell builtins. Avoid repeated calls of `git ls-files` and `awk`. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-06-12mergetool: dissect strings with shell variable magic instead of `expr`Johannes Sixt1-9/+11
git-mergetool spawns an enormous amount of processes. For this reason, the test script, t7610, is exceptionally slow, in particular, on Windows. Most of the processes are invocations of git. There are also some that can be replaced with shell builtins. Do so with `expr`. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-05-13mergetool: use get_merge_tool functionDenton Liu1-8/+4
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]: https://github.com/thenigan/git-diffall Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-10-25mergetool: accept -g/--[no-]gui as argumentsDenton Liu1-2/+9
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 <liu.denton@gmail.com> Signed-off-by: Anmol Mago <anmolmago@gmail.com> Signed-off-by: Brian Ho <briankyho@gmail.com> Signed-off-by: David Lu <david.lu97@outlook.com> Signed-off-by: Ryan Wang <shirui.wang@hotmail.com> Acked-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-13mergetool: don't suggest to continue after last fileNicholas Guriev1-3/+5
Eliminate an unnecessary prompt to continue after failed merger, by not calling the prompt_after_failed_merge function when only one iteration remains. Uses positional parameters to count files in the list to make it easier to see if we have any more paths to process from within the loop. Signed-off-by: Nicholas Guriev <guriev-ns@ya.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-01-10mergetool: fix running in subdir when rerere enabledRichard Hansen1-2/+15
"git mergetool" (without any pathspec on the command line) that is not run from the top-level of the working tree no longer works in Git v2.11, failing to get the list of unmerged paths from the output of "git rerere remaining". This regression was introduced by 57937f70a0 ("mergetool: honor diff.orderFile", 2016-10-07). This is because the pathnames output by the 'git rerere remaining' command are relative to the top-level directory but the 'git diff --name-only' command expects its pathname arguments to be relative to the current working directory. To make everything consistent, cd_to_toplevel before running 'git diff --name-only' and adjust any relative pathnames. Signed-off-by: Richard Hansen <hansenr@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-01-10mergetool: take the "-O" out of $orderfileRichard Hansen1-2/+2
This will make it easier for a future commit to convert a relative orderfile pathname to either absolute or relative to the top-level directory. It also improves code readability. Signed-off-by: Richard Hansen <hansenr@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-10-11mergetool: honor -O<orderfile>David Aguilar1-2/+7
Teach mergetool to pass "-O<orderfile>" down to `git diff` when specified on the command-line. Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: David Aguilar <davvid@gmail.com> Reviewed-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-10-11mergetool: honor diff.orderFileDavid Aguilar1-15/+15
Teach mergetool to get the list of files to edit via `diff` so that we gain support for diff.orderFile. Suggested-by: Luis Gutierrez <luisgutz@gmail.com> Helped-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: David Aguilar <davvid@gmail.com> Reviewed-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-10-11mergetool: move main program flow into a main() functionDavid Aguilar1-87/+93
Make it easier to follow the program's flow by isolating all logic into functions. Isolate the main execution code path into a single unit instead of having prompt_after_failed_merge() interrupt it partyway through. The use of a main() function is borrowing a convention from C, Python, Perl, and many other languages. This helps readers more familiar with other languages understand the purpose of each function when diving into the codebase with fresh eyes. Signed-off-by: David Aguilar <davvid@gmail.com> Reviewed-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-10-11mergetool: add copyrightDavid Aguilar1-0/+1
Signed-off-by: David Aguilar <davvid@gmail.com> Reviewed-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-05-03Merge branch 'nf/mergetool-prompt'Junio C Hamano1-1/+1
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ó1-1/+1
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 <john@keeping.me.uk> Signed-off-by: Nikola Forró <nforro@redhat.com> Acked-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-03-10mergetool: honor tempfile configuration when resolving delete conflictsDavid Aguilar1-1/+10
Teach resolve_deleted_merge() to honor the mergetool.keepBackup and mergetool.keepTemporaries configuration knobs. This ensures that the worktree is kept pristine when resolving deletion conflicts with the variables both set to false. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-03-10mergetool: support delete/delete conflictsDavid Aguilar1-3/+11
If two branches each move a file into different directories then mergetool will fail because it assumes that the file being merged, and its parent directory, are present in the worktree. Create the merge file's parent directory to allow using the deleted base version of the file for merge resolution when encountering a delete/delete conflict. The end result is that a delete/delete conflict is presented for the user to resolve. Reported-by: Joe Einertson <joe@kidblog.org> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-20mergetool--lib: set IFS for difftool and mergetoolDavid Aguilar1-2/+0
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 <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-21mergetool: simplify conditionalsDavid Aguilar1-11/+5
Combine the $last_status checks into a single conditional. Replace $last_status and $rollup_status with a single variable. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-21Merge branch 'da/mergetool-temporary-directory'Junio C Hamano1-4/+31
Allow a temporary directory specified to be used while running "git mergetool" backend. * da/mergetool-temporary-directory: t7610-mergetool: add test cases for mergetool.writeToTemp mergetool: add an option for writing to a temporary directory
2014-10-21Merge branch 'da/mergetool-tool-help'Junio C Hamano1-1/+8
Allow "git mergetool --help" to run outside a Git repository. * da/mergetool-tool-help: difftool: don't assume that default sh is sane mergetool: don't require a work tree for --tool-help git-sh-setup: move GIT_DIR initialization into a function mergetool: use more conservative temporary filenames test-lib-functions: adjust style to match CodingGuidelines t7610-mergetool: prefer test_config over git config
2014-10-21Merge branch 'da/mergetool-temporary-filename'Junio C Hamano1-5/+11
Tweak the names of the three throw-away files "git mergetool" comes up with to feed the merge tool backend, so that a file with a single dot in its name in the original (e.g. "hello.c") will have only one dot in these variants (e.g. "hello_BASE_4321.c"). * da/mergetool-temporary-filename: mergetool: use more conservative temporary filenames
2014-10-16mergetool: add an option for writing to a temporary directoryDavid Aguilar1-4/+31
Teach mergetool to write files in a temporary directory when 'mergetool.writeToTemp' is true. This is helpful for tools such as Eclipse which cannot cope with multiple copies of the same file in the worktree. Suggested-by: Charles Bailey <charles@hashpling.org> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-16mergetool: use more conservative temporary filenamesDavid Aguilar1-5/+11
Avoid filenames with multiple dots so that overly-picky tools do not misinterpret their extension. Previously, foo/bar.ext in the worktree would result in e.g. ./foo/bar.ext.BASE.1234.ext This can be improved by having only a single .ext and using underscore instead of dot so that the extension cannot be misinterpreted. The resulting path becomes: ./foo/bar_BASE_1234.ext Suggested-by: Sergio Ferrero <sferrero@ensoftcorp.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-15difftool: don't assume that default sh is saneCharles Bailey1-0/+4
git-difftool used to create a command list script containing $( ... ) and explicitly calls "sh -c" with this list. Instead, allow mergetool --tool-help to take a mode parameter and call mergetool directly to invoke the show_tool_help function. This mode parameter is intented for use solely by difftool. Signed-off-by: Charles Bailey <cbailey32@bloomberg.net> Helped-by: John Keeping <john@keeping.me.uk> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-15mergetool: don't require a work tree for --tool-helpCharles Bailey1-1/+4
Signed-off-by: Charles Bailey <cbailey32@bloomberg.net> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-15mergetool: use more conservative temporary filenamesDavid Aguilar1-5/+11
Avoid filenames with multiple dots so that overly-picky tools do not misinterpret their extension. Previously, foo/bar.ext in the worktree would result in e.g. ./foo/bar.ext.BASE.1234.ext This can be improved by having only a single .ext and using underscore instead of dot so that the extension cannot be misinterpreted. The resulting path becomes: ./foo/bar_BASE_1234.ext Suggested-by: Sergio Ferrero <sferrero@ensoftcorp.com> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-09git-mergetool.sh: avoid "test <cond> -a/-o <cond>"Elia Pinto1-2/+2
The construct is error-prone; "test" being built-in in most modern shells, the reason to avoid "test <cond> && test <cond>" spawning one extra process by using a single "test <cond> -a <cond>" no longer exists. Signed-off-by: Elia Pinto <gitter.spiros@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-04-22mergetool: run prompt only if guessed toolFelipe Contreras1-3/+11
It's annoying to see the prompt: Hit return to start merge resolution tool (foo): Every time the user does 'git mergetool' even if the user already configured 'foo' as the wanted tool. Display this prompt only when the user hasn't explicitly configured a tool. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Acked-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-14Merge branch 'al/mergetool-printf-fix'Junio C Hamano1-1/+1
* al/mergetool-printf-fix: difftool--helper: fix printf usage git-mergetool: print filename when it contains %
2013-02-08git-mergetool: print filename when it contains %Asheesh Laroia1-1/+1
If git-mergetool was invoked with files with a percent sign (%) in their names, it would print an error. For example, if you were calling mergetool on a file called "%2F": printf: %2F: invalid directive Do not pass random string to printf as if it were a valid format. Use format string "%s" and pass the string as data to be formatted instead. Signed-off-by: Asheesh Laroia <asheesh@asheesh.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-25git-mergetool: move show_tool_help to mergetool--libJohn Keeping1-37/+0
This is the first step in unifying "git difftool --tool-help" and "git mergetool --tool-help". Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-08-23mergetool: style fixesJunio C Hamano1-273/+308
This script is one of the sizeable ones that tempted people to copy its "neibouring style" in their new code, but was littered with styles incompatible with our style guide. - use one tab, not four spaces, per indent level; - long lines can be wrapped after '|', '&&', or '||' for readability. - structures like "if .. then .. else .. fi", "while .. do .. done" are split into lines in such a way that does not require unnecessary semicolon. - case, esac and case-arms align at the same column. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-23mergetool: support --tool-help option like difftool doesJunio C Hamano1-1/+41
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 <gitster@pobox.com>
2012-01-23mergetool: Provide an empty file when neededDavid Aguilar1-4/+8
Some merge tools cannot cope when $LOCAL, $BASE, or $REMOTE are missing. $BASE can be missing when two branches independently add the same filename. Provide an empty file to make these tools happy. When a delete/modify conflict occurs, $LOCAL and $REMOTE can also be missing. We have special case code to handle such case so this change may not affect that codepath, but try to be consistent and create an empty file for them anyway. Reported-by: Jason Wenger <jcwenger@gmail.com> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-10Merge branch 'jm/mergetool-pathspec'Junio C Hamano1-49/+27
* jm/mergetool-pathspec: mergetool: no longer need to save standard input mergetool: Use args as pathspec to unmerged files
2011-09-26mergetool: no longer need to save standard inputJunio C Hamano1-6/+4
Earlier code wanted to run merge_file and prompt_after_failed_merge both of which wanted to read from the standard input of the entire script inside a while loop, which read from a pipe, and in order to do so, it redirected the original standard input to another file descriptor. We no longer need to do so after the previous change. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-09-26mergetool: Use args as pathspec to unmerged filesJonathon Mah1-48/+28
Mergetool now treats its path arguments as a pathspec (like other git subcommands), restricting action to the given files and directories. Files matching the pathspec are filtered so mergetool only acts on unmerged paths; previously it would assume each path argument was in an unresolved state, and get confused when it couldn't check out their other stages. Running "git mergetool subdir" will prompt to resolve all conflicted blobs under subdir. Signed-off-by: Jonathon Mah <me@JonathonMah.com> Acked-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-09-19git-mergetool: check return value from readJay Soffian1-1/+1
Mostly fixed already by 6b44577 (mergetool: check return value from read, 2011-07-01). Catch two uses it missed. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-07-01mergetool: check return value from readJunio C Hamano1-4/+4
The process may not even have the standard input open in which case it will get stuck in an infinite loop to prompt and read nothing. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-13mergetool: Teach about submodulesJonathon Mah1-6/+84
When the index has conflicted submodules, mergetool used to mildly clobber the module, renaming it to mymodule.BACKUP.nnnn, then failing to copy it non-recursively. Recognize submodules and offer a resolution instead: Submodule merge conflict for 'Shared': {local}: submodule commit ad9f12e3e6205381bf2163a793d1e596a9e211d0 {remote}: submodule commit f5893fb70ec5646efcd9aa643c5136753ac89253 Use (l)ocal or (r)emote, or (a)bort? Selecting a commit will stage it, but not update the submodule (as git does had there been no conflict). Type changes are also supported, should the path be a submodule on one side, and a file, symlink, directory, or deleted on the other. Signed-off-by: Jonathon Mah <me@JonathonMah.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-02-16mergetool: don't skip modify/remove conflictsMartin von Zweigbergk1-1/+1
Since bb0a484 (mergetool: Skip autoresolved paths, 2010-08-17), mergetool uses different ways of figuring out the list of files with merge conflicts depending on whether rerere is active. If rerere is active, mergetool will use 'git rerere status' to list the files with remaining conflicts. However, the output from that command does not list conflicts of types that rerere does not handle, such as modify/remove conflicts. Another problem with solely relying on the output from 'git rerere status' is that, for new conflicts that are not yet known to rerere, the output from the command will list the files even after adding them to the index. This means that if the conflicts in some files have been resolved and 'git mergetool' is run again, it will ask the user something like the following for each of those files. file1: file does not need merging Continue merging other unresolved paths (y/n) ? Solve both of these problems by replacing the call to 'git rerere status' with a call to the new 'git rerere remaining' that was introduced in the previous commit. Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-03Merge branch 'cb/maint-mergetool-no-tty'Junio C Hamano1-2/+6
* cb/maint-mergetool-no-tty: mergetool: Remove explicit references to /dev/tty Conflicts: git-mergetool.sh
2010-08-20mergetool: Remove explicit references to /dev/ttyCharles Bailey1-2/+6
mergetool used /dev/tty to switch back to receiving input from the user via inside a block with a redirected stdin. This harms testability, so change mergetool to save its original stdin to an alternative fd in this block and restore it for those sub-commands that need the original stdin. Includes additional compatibility fix from Jonathan Nieder. Tested-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-17mergetool: Skip autoresolved pathsDavid Aguilar1-5/+23
When mergetool is run without path limiters it loops over each entry in 'git ls-files -u'. This includes autoresolved paths. Teach mergetool to only merge files listed in 'rerere status' when rerere is enabled. There are some subtle but harmless changes in behavior. We now call cd_to_toplevel when no paths are given. We do this because 'rerere status' paths are always relative to the root. This is beneficial for the non-rerere use as well in that mergetool now runs against all unmerged files regardless of the current directory. This also slightly tweaks the output when run without paths to be more readable. The old output: Merging the files: foo bar baz The new output: Merging: foo bar baz Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-12mergetool--lib: simplify API usage by removing more global variablesDavid Aguilar1-7/+8
The mergetool--lib scriplet was tricky to use because it relied upon the existance of several global shell variables. This removes more global variables so that things are simpler for callers. A side effect is that some variables are recomputed each time run_merge_tool() is called, but the overhead for recomputing them is justified by the simpler implementation. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-11Fix misspelled mergetool.keepBackupFerry Huberts1-1/+1
In several places mergetool.keepBackup was misspelled as merge.keepBackup. Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-08difftool/mergetool: refactor commands to use git-mergetool--libDavid Aguilar1-211/+13
This consolidates the common functionality from git-mergetool and git-difftool--helper into a single git-mergetool--lib scriptlet. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-07mergetool: use $( ... ) instead of `backticks`David Aguilar1-8/+8
This makes mergetool consistent with Documentation/CodingGuidelines. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-07difftool/mergetool: add diffuse as merge and diff toolSebastian Pipping1-2/+2
This adds diffuse as a built-in merge tool. Signed-off-by: Sebastian Pipping <sebastian@pipping.org> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-07git-mergetool: add new merge tool TortoiseMergeMarkus Heidelberg1-3/+13
TortoiseMerge comes with TortoiseSVN or TortoiseGit for Windows. It can only be used as a merge tool with an existing base file. It cannot be used without a base nor as a diff tool. The documentation only mentions the slash '/' as command line option prefix, which refused to work, but the parser also accepts the dash '-' See http://code.google.com/p/msysgit/issues/detail?id=226 Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-07git-mergetool/difftool: make (g)vimdiff workable under WindowsMarkus Heidelberg1-2/+8
Under Windows vimdiff and gvimdiff are not available as symbolic links, but as batch files vimdiff.bat and gvimdiff.bat. These files weren't found by 'type vimdiff' which led to the following error: The merge tool vimdiff is not available as 'vimdiff' Even if they were found, it wouldn't work to invoke these batch files from git-mergetool. To solve this, use vim and gvim (vim.exe and gvim.exe) and pass the -d command line switch over to them. Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-02-05Merge branch 'cb/mergetool'Junio C Hamano1-4/+11
* cb/mergetool: mergetool: fix running mergetool in sub-directories mergetool: Add a test for running mergetool in a sub-directory mergetool: respect autocrlf by using checkout-index
2009-01-31mergetool: fix running mergetool in sub-directoriesCharles Bailey1-5/+4
The previous fix to mergetool to use checkout-index instead of cat-file broke running mergetool anywhere except the root of the repository. This fixes it by using the correct relative paths for temporary files and index paths. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-27mergetool: respect autocrlf by using checkout-indexCharles Bailey1-3/+11
Previously, git mergetool used cat-file which does not perform git to worktree conversion. This changes mergetool to use git checkout-index instead which means that the temporary files used for mergetool use the correct line endings for the platform. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-27mergetool: Don't repeat merge tool candidatesJohannes Gilger1-10/+8
git mergetool listed some candidates for mergetools twice, depending on the environment. This slightly changes the behavior when both KDE_FULL_SESSION and GNOME_DESKTOP_SESSION_ID are set at the same time; in such a case meld is used in favor of kdiff3 (the old code favored kdiff3 in such a case), but it should not matter in practice. Signed-off-by: Johannes Gilger <heipei@hackvalue.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-18mergetool: put the cursor on the editable file for VimMarkus Heidelberg1-2/+7
When resolving conflicts, you only need to edit the $MERGED file. Put the cursor automatically into its window for vimdiff and gvimdiff to avoid doing <C-w>l every time. Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de> Tested-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-01Merge branch 'cb/mergetool'Junio C Hamano1-30/+80
* cb/mergetool: mergetool: Don't keep temporary merge files unless told to mergetool: Add prompt to continue after failing to merge a file Add -y/--no-prompt option to mergetool Fix some tab/space inconsistencies in git-mergetool.sh
2008-12-19git-mergetool: properly handle "git mergetool -- filename"David Aguilar1-0/+1
Like many git commands, git-mergetool allows "--" to signal the end of option processing. This adds a missing "shift" statement so that this is correctly handled. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-12-12mergetool: Don't keep temporary merge files unless told toCharles Bailey1-0/+6
This changes git mergetool to remove the temporary files used to invoke the merge tool even if it returns non-zero. This also adds a configuration option (mergetool.keepTemporaries) to retain the previous behaviour if desired. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-12-12mergetool: Add prompt to continue after failing to merge a fileCharles Bailey1-9/+43
This option stops git mergetool from aborting at the first failed merge. After a failed merge the user will be prompted to indicated whether he wishes to continue with attempting to merge subsequent paths or to abort. This allows some additional use patterns. Merge conflicts can now be previewed one at time and merges can also be skipped so that they can be performed in a later pass. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-14Add -y/--no-prompt option to mergetoolCharles Bailey1-3/+13
This option lets git mergetool invoke the conflict resolution program without waiting for a user prompt each time. Also added a mergetool.prompt (default true) configuration variable controlling the same behaviour Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-14Fix some tab/space inconsistencies in git-mergetool.shCharles Bailey1-19/+19
git-mergetool.sh mostly uses 8 space tabs and 4 spaces per indent. This change corrects this in a part of the file affect by a later commit in this patch series. diff -w considers this change is to be a null change. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-19Remove the use of '--' in merge program invocationPatrick Higgins1-12/+12
Put a "./" at the beginning of all paths given to the merge program so that filenames beginning with a '-' character don't get interpreted as options. This deals with a problem where kdiff3 can be compiled with or without support for the '--' separator between options and filenames. Signed-off-by: Patrick Higgins <patrick.higgins@cexp.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-11mergetool: Make ECMerge use the settings as specified by the user in the GUISebastian Schuberth1-2/+2
When run from the command line, ECMerge does not automatically use the same settings for a merge / diff that it would use when starting the GUI and loading files manually. In the first case the built-in factory defaults would be used, while in the second case the settings the user has specified in the GUI would be used, which can be misleading. Specifying the "--default" command line option changes this behavior so that always the user specfified GUI settings are used. Signed-off-by: Sebastian Schuberth <sschuberth@visageimaging.com> Tested-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-05Teach git mergetool to use custom commands defined at config timeCharles Bailey1-2/+26
Currently git mergetool is restricted to a set of commands defined in the script. You can subvert the mergetool.<tool>.path to force git mergetool to use a different command, but if you have a command whose invocation syntax does not match one of the current tools then you would have to write a wrapper script for it. This patch adds two git config variable patterns which allow a more flexible choice of merge tool. If you run git mergetool with -t/--tool or the merge.tool config variable set to an unrecognized tool then git mergetool will query the mergetool.<tool>.cmd config variable. If this variable exists, then git mergetool will treat the specified tool as a custom command and will use a shell eval to run the command with the documented shell variables set. mergetool.<tool>.trustExitCode can be used to indicate that the exit code of the custom command can be used to determine the success of the merge. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-05Changed an internal variable of mergetool to support custom commandsCharles Bailey1-50/+50
The variable $path changes to $MERGED so that it is more consistent with $BASE, $LOCAL and $REMOTE for future custom command lines. Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-05Tidy up git mergetool's backup file behaviourCharles Bailey1-24/+13
Currently a backup pre-merge file with conflict markers is sometimes kept with a .orig extenstion and sometimes removed depending on the particular merge tool used. This patch makes the handling consistent across all merge tools and configurable via a new mergetool.keepBackup config variable Signed-off-by: Charles Bailey <charles@hashpling.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-01-07Allow git-mergetool to handle paths with a leading spaceRogan Dawes1-2/+5
Signed-off-by: Rogan Dawes <rogan@dawes.za.net>
2007-12-05Open external merge tool with original file extensions for all three filesPini Reznik1-4/+5
Before this change, conflicted files were open in external merge tool with temporary filenames like REMOTE.$$ and LOCAL.$$. This way meld was unable to recognize these files and syntax highlighting feature was unusable. Help such merge tools by giving temporar files the same extension as the original. Signed-off-by: Pini Reznik <pinir@expand.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-06scripts: Add placeholders for OPTIONS_SPECJunio C Hamano1-0/+1
--text follows this line-- These commands currently lack OPTIONS_SPEC; allow people to easily list with "git grep 'OPTIONS_SPEC=$'" what they can help improving. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-10-18mergetool: avoid misleading message "Resetting to default..."Steffen Prohaska1-1/+1
If no mergetool is configured in the configuration variable merge.tool the resetting message should not be printed. This is fixed. The message is only printed if a tool is configured but the entry in merge.tool is invalid. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-10-18mergetool: add support for ECMergeSteffen Prohaska1-1/+11
Add support to mergetool for ECMerge available from http://www.elliecomputing.com/Products/merge_overview.asp Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-10-18mergetool: use path to mergetool in config var mergetool.<tool>.pathSteffen Prohaska1-43/+54
This commit adds a mechanism to provide absolute paths to the external programs called by 'git mergetool'. A path can be specified in the configuation variable mergetool.<tool>.path. The configuration variable is similar to how we name branches and remotes. It is extensible if we need to specify more details about a tool. The mechanism is especially useful on Windows, where external programs are unlikely to be in PATH. [sp: Fixed a few minor issues prior to applying] Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-09-28mergetool: Fix typo in options passed to kdiff3Theodore Ts'o1-2/+2
Fix missing double hyphens in "-L1" and "-L2" Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-09-28mergetool: fix emerge when running in a subdirectoryTheodore Ts'o1-2/+2
Only pass the basename of the output filename when to emerge, since emerge interprets non-absolute pathnames relative to the containing directory of the output buffer. Thanks to Kelvie Wong for pointing this out. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-09-28Mergetool generating blank files (1.5.3)Junio C Hamano1-3/+4
When mergetool is run from a subdirectory, "ls-files -u" nicely limits the output to conflicted files in that directory, but we need to give the full path to cat-file plumbing to grab the contents of stages. Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-09-23Supplant the "while case ... break ;; esac" idiomDavid Kastrup1-1/+1
A lot of shell scripts contained stuff starting with while case "$#" in 0) break ;; esac and similar. I consider breaking out of the condition instead of the body od the loop ugly, and the implied "true" value of the non-matching case is not really obvious to humans at first glance. It happens not to be obvious to some BSD shells, either, but that's because they are not POSIX-compliant. In most cases, this has been replaced by a straight condition using "test". "case" has the advantage of being faster than "test" on vintage shells where "test" is not a builtin. Since none of them is likely to run the git scripts, anyway, the added readability should be worth the change. A few loops have had their termination condition expressed differently. Signed-off-by: David Kastrup <dak@gnu.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-07-02Rewrite "git-frotz" to "git frotz"Junio C Hamano1-8/+8
This uses the remove-dashes target to replace "git-frotz" to "git frotz". Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-06-10git-mergetool: Make default selection of merge-tool more intelligentTheodore Ts'o1-17/+29
Make git-mergetool prefer meld under GNOME, and kdiff3 under KDE. When considering emerge and vimdiff, check $VISUAL and $EDITOR to see which the user might prefer. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: Josh Triplett <josh@freedesktop.org>
2007-06-10[PATCH] git-mergetool: Allow gvimdiff to be used as a mergetoolDan McGee1-2/+10
Signed-off-by: Dan McGee <dpmcgee@gmail.com> Acked-by: "Theodore Ts'o" <tytso@mit.edu>
2007-06-06Fix typo in git-mergetoolJosh Triplett1-1/+1
Signed-off-by: Josh Triplett <josh@freedesktop.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-03-29mergetool: Clean up description of files and prompts for merge resolutionsTheodore Ts'o1-12/+15
This fixes complaints from Junio for how messages and prompts are printed when resolving symlink and deleted file merges. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: Make git-rm quiet when resolving a deleted file conflictTheodore Ts'o1-1/+1
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: Add support for Apple Mac OS X's opendiff commandTheodore Ts'o1-2/+14
Signed-off-by: Arjen Laarhoven <arjen@yaph.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: Fix abort command when resolving symlinks and deleted filesTheodore Ts'o1-4/+4
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: Remove spurious error message if merge.tool config option not setTheodore Ts'o1-1/+1
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: factor out common codeTheodore Ts'o1-42/+36
Create common function check_unchanged(), save_backup() and remove_backup(). Also fix some minor whitespace issues while we're at it. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: portability fix: don't use reserved word functionTheodore Ts'o1-5/+5
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: portability fix: don't assume true is in /binTheodore Ts'o1-2/+2
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: Don't error out in the merge case where the local file is deletedTheodore Ts'o1-6/+5
If the file we are trying to merge resolve is in git-ls-files -u, then skip the file existence test. If the file isn't reported in git-ls-files, then check to see if the file exists or not to give an appropriate error message. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-29mergetool: Replace use of "echo -n" with printf(1) to be more portableTheodore Ts'o1-14/+12
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-18mergetool: print an appropriate warning if merge.tool is unknownTheodore Ts'o1-4/+9
Also add support for vimdiff Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-18mergetool: Add support for vimdiff.James Bowes1-3/+5
Signed-off-by: James Bowes <jbowes@dangerouslyinc.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-03-13Add git-mergetool to run an appropriate merge conflict resolution programTheodore Ts'o1-0/+352
The git-mergetool program can be used to automatically run an appropriate merge resolution program to resolve merge conflicts. It will automatically run one of kdiff3, tkdiff, meld, xxdiff, or emacs emerge programs. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>