libgit2 / libgit2/libgit2sharp

Diff class not mockable

オープン
#1,856 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

LibGit2Sharp/Diff.cs、特に internal constructor、Compare、WorkdirToIndex から始め、続いて LibGit2Sharp/Commands/Stage.cs からの呼び出しを追跡します。issue に記載されているモックされたリポジトリを使った Commands.Stage のシナリオを再現します。完了の条件は、使用可能な Diff を構築するためにその経路が reflection に依存しなくなり、リポジトリが null であることが原因で失敗しないことです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp
領域
devtools
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。