Search code examples
libgit2sharp

Show conflicts when pulling using libgit2sharp


I'm using libgit2sharp to pull (Commands.Pull) from a remote repo using the default FetchOptions, MergeOptions and PullOptions. My working directory has an uncommitted change that will cause a conflict, and as expected I get a CheckOutConflictException with the message "1 conflict prevents checkout".

What I can't figure out is how to programmatically find out the file that is causing the conflict. repo.Index.Conflicts doesn't contain any conflicts, I haven't found any documentation for this case in the wiki, and I can't find any tests for this case in the codebase.

Can anyone show me what I'm missing?


Solution

  • You want to add a CheckoutOptions.OnCheckoutNotify callback, which will notify you every time checkout encounters a path with a particular action.

    In this case, you want to look for conflicts, so set your CheckoutOptions.CheckoutNotifyFlags to listen for CheckoutNotifyFlags.Conflict.

    You will be called back for each file that has a checkout conflict and given the path.