libgit2 / libgit2/libgit2sharp

CheckoutConflictException on Commands.Checkout

未關閉
#1,597 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
C#
星號
3.5k
分支
925
PR 合併指標
30 天內沒有已合併 PR

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從重現的 Commands.Checkout 呼叫、其對 CheckoutConflictException 的處理,以及在 LibGit2Sharp v0.25.2 上觀察到的 Repo.Index ConflictCollection 狀態開始。在所述的 Windows 和 .NET 環境中,使用提供的 Unity 範例比較 checkout 通知旗標和例外行為。完成的標準是解釋例外和衝突狀態行為,或確定所需的文件或修正。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp, git
領域
devtools
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。