开发者

How to make git work with vimdiff and trustExitCode

开发者 https://www.devze.com 2023-03-09 17:58 出处:网络
I have configured vimdiff as mergetool for git. Whenever i do a merge, git never asks wether the merge was successful. I also 开发者_开发知识库tried:

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?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消