libgit2 / libgit2/libgit2sharp

CheckoutConflictException on Commands.Checkout

Open
#1,597 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Description

Hi!

I want to create a UI to make resolving conflicts for a user as easy as possible. At the moment after i have created a conflict by make some changes local and in the repository in the same line of the same file, i want to do first a checkout to get informations about the conflicted file

Reproduction steps

Here is my code to make the checkout of a given Repository:

public void Checkout()
    {
        try
        {
            UnityEngine.Debug.Log("starting checkout");
            CheckoutOptions opts = new CheckoutOptions();
            opts.OnCheckoutNotify = (string path, CheckoutNotifyFlags notify) =>
            {
                switch (notify)
                {
                    case CheckoutNotifyFlags.Conflict:
                        UnityEngine.Debug.Log("conflicted file found at: " + path);
                        return true;
                    case CheckoutNotifyFlags.Ignored:
                        UnityEngine.Debug.Log("ignored file found at: " + path);
                        return true;
                    case CheckoutNotifyFlags.None:
                        UnityEngine.Debug.Log("unchanged file found at: " + path);
                        return true;
                    case CheckoutNotifyFlags.Untracked:
                        UnityEngine.Debug.Log("untracked file found at: " + path);
                        return true;
                    case CheckoutNotifyFlags.Updated:
                        UnityEngine.Debug.Log("updated file found at: " + path);
                        return true;
                    default:
                        UnityEngine.Debug.Log("dirty file at: " + path);
                        return true;
                }
            };
            opts.CheckoutNotifyFlags = CheckoutNotifyFlags.None |
                                       CheckoutNotifyFlags.Dirty |
                                       CheckoutNotifyFlags.Ignored |
                                       CheckoutNotifyFlags.Conflict |
                                       CheckoutNotifyFlags.Untracked |
                                       CheckoutNotifyFlags.Updated;
            

            Branch actualRemote = Repo.Branches["origin/" + Repo.Head.FriendlyName];
            Commands.Checkout(Repo, actualRemote.Tip.Tree, opts, "");
        }
        catch (CheckoutConflictException e)
        {
            UnityEngine.Debug.Log(e.Message);
        }
    }

Repo is the actual Repository, and it contains in my test example 1 conflicted file.

Expected behavior

I don't find any detailed guide, how to resolve conflicts with LibGit2Sharp, but if i understand it right, the checkout command should write the conflicted files in the ConflictCollection of the index of the repository.

Actual behavior

If i do the checkout with the code above, the conflicted file(s) will be found, but the catch-clause will be triggered and the ConflictCollection of Repo.Index will be still empty. Can somebody explain how this whole process works, how i can use it right and why the exception in the code will be triggered?

Version of LibGit2Sharp (release number or SHA1)

LibGit2Sharp v0.25.2

Operating system(s) tested; .NET runtime tested

Win 10 64bit, .NET Framework 4.6.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced Commands.Checkout call, its CheckoutConflictException handling, and the observed Repo.Index ConflictCollection state on LibGit2Sharp v0.25.2. Compare the checkout notification flags and exception behavior using the supplied Unity example on the stated Windows and .NET environment. Done means explaining the exception and conflict-state behavior, or identifying the required documentation or correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.