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