libgit2 / libgit2/libgit2sharp
Diff class not mockable
還沒有人認領這個 Issue。
- 主要語言
- C#
- 星號
- 3.5k
- 分支
- 925
- PR 合併指標
- 30 天內沒有已合併 PR
描述
The Diff class is not very mockable due to its dependency on a private Repository field that is only set from an internal constructor. I encountered this when attempting to mock a repository and its related object graph and then invoking Commands.Stage with that mocked repository. It resulted in a null ref because the Diff.repo field wasn't set.
Commands.Stage ends up calling the internal Diff.Compare method:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Commands/Stage.cs#L77
Compare ends up passing the Diff.repo field to WorkdirToIndex:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Diff.cs#L472
Which then blows up because repo is null:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Diff.cs#L506
The repo field is null because it only gets set by an internal constructor:
https://github.com/libgit2/libgit2sharp/blob/3d7276275e8ea9dce324e437760c31e69b5ec10c/LibGit2Sharp/Diff.cs#L90
This prevents a good mocking solution because the internal constructor can't be called without reflection.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 LibGit2Sharp/Diff.cs 開始,特別查看內部建構函式、Compare 和 WorkdirToIndex,接著追蹤來自 LibGit2Sharp/Commands/Stage.cs 的呼叫。重現 issue 中描述的使用模擬 repository 的 Commands.Stage 情境。完成的標準是:該路徑不再依賴 reflection 來建構可用的 Diff,且不會因為其 repository 為 null 而失敗。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- csharp
- 領域
- devtools
- Issue 類型
- 重構
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100