Ignoring whitespaces on diff does not work

Offen
#1,858 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
csharp, git
Bereich
devtools

Rechercherichtung

Beginne damit, das Compare-Beispiel mit CompareOptions, SimilarityOptions und WhitespaceMode.IgnoreAllWhitespace nachzubilden, und vergleiche dann seine Ausgabe mit git diff --ignore-all-space. Verfolge den Diff-Vergleichspfad, der Whitespace-Modi verarbeitet. Als abgeschlossen gilt die Aufgabe, wenn Änderungen, die ausschließlich aus Whitespace bestehen, ignoriert werden, während substanzielle Änderungen weiterhin im Patch erscheinen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
C#
Sterne
3.5k
Forks
925
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus libgit2/libgit2sharp

Alle Issues in libgit2/libgit2sharp

Ähnliche Issues

Weitere Issues zu C#

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.