4

I have configured vimdiff as mergetool for git. Whenever i do a merge, git never asks wether the merge was successful. I also tried:

git config --global mergetool.vimdiff.trustExitCode false

with no difference. Still no question after i leave vimdiff with :wqa and i have to manually remove stale *.orig files.

Maybe related: When i display config settings trustExitCode is not displayed with camelcase anymore:

git config --global -l

core.editor=vim
core.autocrlf=input
merge.tool=vimdiff
alias.co=checkout
alias.st=status
color.diff=auto
color.status=auto
color.branch=auto
mergetool.vimdiff.trustexitcode=false

How can this be fixed?

Michael Härtl
  • 8,428
  • 5
  • 35
  • 62

3 Answers3

4

I know this is an old question, but I just ran into the same issue.

The part about manually removing stale backup files can be fixed with:

git config --global mergetool.vimdiff.keepBackup false

I think other problem is that trustExitCode doesn't do what you think it does:

mergetool.<tool>.trustExitCode

For a custom merge command, specify whether the exit code of the merge command can be used to determine whether the merge was successful. If this is not set to true then the merge target file timestamp is checked and the merge assumed to have been successful if the file has been updated, otherwise the user is prompted to indicate the success of the merge.

So, even with this option set to false, it will only prompt you if the file hasn't been changed.

Community
  • 1
  • 1
xthrd
  • 252
  • 3
  • 11
  • The configuration `keepBackup` must not include `vimdiff`, it is a setting independent of the mergetool used. Thus the correct command is `git config --global mergetool.keepBackup false`. – siegi Dec 18 '14 at 01:00
  • @siegi Actually, the `keepBackup` setting can be applied to either one. If you use `mergetool.keepBackup` it will apply to all merge tools, but if you use `mergetool.vimdiff.keepBackup` it will only apply to vimdiff. I have not had the same problem with other merge tools, so it seems appropriate to only apply the setting to vim. – xthrd Dec 19 '14 at 02:55
  • I agree that a tool specific setting would make sense and I also expected Git would behave as you described it. But I just retried it with `mergetool.vimdiff.keepBackup` and it did not work. Setting `mergetool.keepBackup` however did work. May be it depends on the Git version used - I'm running 2.1.3. – siegi Dec 19 '14 at 16:00
  • @siegi After a quick look at the man page, you are correct. I don't know if it was different before, or I was simply mistaken. Thanks for pointing that out. – xthrd Dec 19 '14 at 20:11
3

I know this isn't really an answer to your question, but I think you should checkout a vim plugin called Fugitive.

There's even a screencast on resolving merge conflicts with vimdiff

It basically offers all (or most of) the git functionality you find in the terminal, but within vim in a way that really makes sense. Hope that helps and good luck :D.

jtsao22
  • 1,962
  • 1
  • 13
  • 13
2

With trustExitCode set (which seems to be the default for vimdiff) you will need to exit vim with a non-zero exit code for git to recognize the files as not merged.

In vim this means using :cq[uit] to exit. Take note that :cq behaves like :qall!, meaning it silently discards all unsaved changes and quits vim (with a non-zero exit code).

When doing this (git v2.14.2.windows.1; git bash; vim 8.0.606) git writes

merge of exampleFile.cpp failed
Continue merging other unresolved paths [y/n]?

And it leaves the file in a conflicting state. If I would have exited with :qall! the conflict might still be in the file, but git would have marked it as resolved.

As to why git still accepts it as resolved when using trustExitCode = false, I am a bit unsure. When opening a file with git mergetool the timestamp is updated to the current time, which seems to indicate that vimdiff (or git) is touching the file. This might be the reason git won't ask for confirmation ofd the conflict resolution as it sees the updated time stamp and assumes the file was resolved.

Loebl
  • 1,381
  • 11
  • 21