Search code examples
c#.netgitlibgit2libgit2sharp

LibGit2Sharp 1 conflict prevent from checkout


I currently have the problem, that my application using libgit2sharp always crashs witht the message:

1 conflict prevents from checkout

when trying to call repo.Pull

The curious thing is, if i print the status of the local repository, their are no changes in the repository.

I even tried resetting the repository at first, or checking the files out, but nothing helps. This is my code:

using (LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(path))
{
    var tipId = repo.Head.Tip.Tree;
    Log.LogManagerInstance.Instance.Info("HEAD tree id: " + tipId.Id.ToString());

    // Pull changes
    PullOptions options = new PullOptions();

    options.FetchOptions = new FetchOptions();
    options.MergeOptions = new MergeOptions();

    // ! Only for trying to fix the bug. Should not be here
    options.MergeOptions.FileConflictStrategy = CheckoutFileConflictStrategy.Theirs;

    repo.Reset(repo.Head.Tip);
    // ! --

    options.FetchOptions.CredentialsProvider = CredentialsHandler;

    Log.LogManagerInstance.Instance.Info("Try pull from remote repository");

    // Pull changes from network
    var result = repo.Network.Pull(new LibGit2Sharp.Signature(username, mail, new DateTimeOffset(DateTime.Now)), options);

    if (result != null && result.Commit != null)
    {
        Log.LogManagerInstance.Instance.Info("Pulled from remote branch, new tree id: " + result.Commit.Tree.Id.ToString());

        // get difference in the git tree (file-system)
        var diffs = repo.Diff.Compare<TreeChanges>(tipId, result.Commit.Tree);

        MergeTreeChangesToDatabase(diffs, path);
    }
    else
    {
        Log.LogManagerInstance.Instance.Info("Local repository is up-to-date with the remote branch");
    }
}

Thank you very much.

EDIT

Using the pre release 0.22 seems to solve my problem.


Solution

  • The Version 0.22 fix all problems.