How do I make gvimdiff opened by git mergetool open all files at once in tabs?
Asked Answered
D

1

1

Normally git -c merge.tool=gvimdiff mergetool opens files to be merged on by one, in batch mode:

Normal merge conflict for '...':
  {local}: modified file
  {remote}: modified file
4 files to edit
... seems unchanged.
Was the merge successful? [y/n] n
merge of ... failed
Continue merging other unresolved paths (y/n) ? y
Normal merge conflict for '...':
  {local}: modified file
  {remote}: modified file
4 files to edit
modules ... seems unchanged.
Was the merge successful? [y/n] n
merge of modules ... failed
Continue merging other unresolved paths (y/n) ? n

How do I make it open all files at one, with tabs (like in gvim -p file1 file2) that contain the four pane arrangement for each file to be merged?

Dexedrine answered 31/8, 2016 at 21:14 Comment(2)
O
0

git mergetool flow is designed to resolve conflicts in one file a time. Hence what you are asking for cannot be done in a clean way. However it is possible to create a custom mergetool, that will accumulate input from git mergetool in a single gvim window. The hack that this "solution" inevitably has to contain is that it must make the git mergetool flow believe that the custom mergetool has successfully merged the file, even though it just has opened the file in gvim. This is necessary so that the git mergetool flow proceeds to the next file without asking any questions. As a result, if you exit gvim without making any changes, git will still think that all conflicts have been resolved.

A draft version of such a custom mergetool (that opens files in different gvim windows, rather than in tabs) follows:

.gitconfig:

[mergetool "mygvimdiff"]
    cmd=/path/to/mygvimdiff "$MERGED" "$LOCAL" "$BASE" "$REMOTE"
    trustExitCode=true

mygvimdiff:

#!/bin/bash

gvim -d -c "wincmd J" "$@"

# wait till gvim loads the temporary files before
# the git mergetool script deletes them
sleep 1

exit 0

Usage:

git mergetool -t mygvimdiff
Occur answered 1/9, 2016 at 6:2 Comment(2)
Maybe better to fake unsuccessful merge? The mergetool still asks for the next file as far as I experimented.Dexedrine
@Dexedrine Then someone must answer mergetool's confirmation to proceedOccur

© 2022 - 2024 — McMap. All rights reserved.