0

Coming from Spacemacs, one of the things that I miss is that files are automatically git added after all conflicts are resolved. Wondering if there's a way to do that in vim.

1 Answer 1

2

When invoked with git mergetool, where the mergetool.<tool>.trustExitCode variable is true, then exiting Vim will mark the conflict as resolved in Git. Conversely, exiting via :cquit with no arguments (or a non-zero argument) will not cause Git to consider the conflict resolved.


With fugitive, I have merge.tool = fugitive and merge.fugitive.cmd = vim --nofork +\"Git mergetool\", along with the trustExitCode = true as mentioned. Git's support for Vim (sans fugitive) has improved dramatically lately, so you should check the default configurations and adjust them as specified/desired.

4
  • Hmm, I want to not have to worry about the exit code though, I want some autodetection of whether or not it's been resolved...
    – Carl Dong
    Oct 21, 2022 at 17:08
  • @CarlDong and my approach is: it's been resolved if I save-and-quit from Vim normally. If I don't, it hasn't. Git isn't smart enough to inspect the content and tell you the conflict is resolved because it doesn't (and couldn't) understand the content. Perhaps you could describe more (or point to docs) about how Spacemacs knows when the conflicts are resolved?
    – D. Ben Knoble
    Oct 21, 2022 at 19:33
  • Didn't take a look at the Spacemacs code but I just found out that git diff --check will indicate if there are leftover conflict markers. Might use that to script the automation. Thanks!
    – Carl Dong
    Nov 2, 2022 at 0:47
  • I've had Git incorrectly flag a text file with ===== as having conflict markers, so beware false-positives @CarlDong
    – D. Ben Knoble
    Nov 3, 2022 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.