libgit2 / libgit2/libgit2sharp

Ignoring whitespaces on diff does not work

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

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

主要言語
C#
スター
3.5k
フォーク
925
PR マージ指標
30日以内にマージされた PR はありません

説明

Expected behavior

When I call:

  var options =
                new CompareOptions()
                {
                    ContextLines = Int32.MaxValue,
                    IncludeUnmodified = true,
                    Similarity =
                        new SimilarityOptions()
                        {
                            WhitespaceMode = WhitespaceMode.IgnoreAllWhitespace
                        }
                };

Console.Write(
   repo.Diff.Compare<Patch>(
      branch.Tip.Tree, 
      DiffTargets.Index | DiffTargets.WorkingDirectory, 
      files,
      null,
      options
   ).First().Patch
)

the output is the same as using the git command git diff --ignore-all-space:

diff --git a/test.txt b/test.txt
index d209983..b2c9980 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,2 @@
 I am an  initial  content
-I am a changeable content
\ No newline at end of file
+I am a different content
\ No newline at end of file
Actual behavior

If have a file "test.txt" with committed content:

I am an inital content
I am a changeable content

and uncommitted content:

I am an  inital  content
I am a different content

(The first line has some additional whitespaces)

When I call:

  var options =
                new CompareOptions()
                {
                    ContextLines = Int32.MaxValue,
                    IncludeUnmodified = true,
                    Similarity =
                        new SimilarityOptions()
                        {
                            WhitespaceMode = WhitespaceMode.IgnoreAllWhitespace
                        }
                };

Console.Write(
   repo.Diff.Compare<Patch>(
      branch.Tip.Tree, 
      DiffTargets.Index | DiffTargets.WorkingDirectory, 
      files,
      null,
      options
   ).First().Patch
)

the output is

diff --git a/test.txt b/test.txt
index d209983..b2c9980 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,2 @@
-I am an initial content
-I am a changeable content
\ No newline at end of file
+I am an  initial  content
+I am a different content
\ No newline at end of file
Version of LibGit2Sharp (release number or SHA1)

v0.26.2

Operating system(s) tested; .NET runtime tested

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

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

はじめの一歩

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

調査の方向性

まず、CompareOptions、SimilarityOptions、WhitespaceMode.IgnoreAllWhitespace を使って Compare の例を再現し、その出力を git diff --ignore-all-space と比較します。Whitespace モードを処理する diff 比較の経路を追跡します。Whitespace のみの変更が無視され、実質的な変更が引き続きパッチに表示されれば完了です。

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

評価

技術スタック
csharp, git
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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