libgit2 / libgit2/libgit2sharp
Ignoring whitespaces on diff does not work
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Compare example with CompareOptions, SimilarityOptions, and WhitespaceMode.IgnoreAllWhitespace, then compare its output with git diff --ignore-all-space. Trace the diff comparison path that handles whitespace modes. Done means whitespace-only changes are ignored while substantive changes still appear in the patch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100