8000 Make Diff.Compare consider untracked changes · gitextensions/libgit2sharp@e1205a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1205a2

Browse files
mm201nulltoken
authored andcommitted
Make Diff.Compare consider untracked changes
1 parent ce5ccef commit e1205a2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,19 @@ public void CanCompareTheWorkDirAgainstTheIndex()
3535
Assert.Equal("modified_unstaged_file.txt", changes.Modified.Single().Path);
3636
}
3737
}
38+
39+
[Fact]
40+
public void CanCompareTheWorkDirAgainstTheIndexWithUntrackedFiles()
41+
{
42+
using (var repo = new Repository(StandardTestRepoPath))
43+
{
44+
TreeChanges changes = repo.Diff.Compare(null, true);
45+
46+
Assert.Equal(3, changes.Count());
47+
Assert.Equal("deleted_unstaged_file.txt", changes.Deleted.Single().Path);
48+
Assert.Equal("modified_unstaged_file.txt", changes.Modified.Single().Path);
49+
Assert.Equal("new_untracked_file.txt", changes.Added.Single().Path);
50+
}
51+
}
3852
}
3953
}

LibGit2Sharp/Diff.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnume
201201
/// Show changes between the working directory and the index.
202202
/// </summary>
203203
/// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
204+
/// <param name = "includeUntracked">If true, include untracked files from the working dir as additions. Otherwise ignore them.</param>
204205
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the working directory and the index.</returns>
205-
public virtual TreeChanges Compare(IEnumerable<string> paths = null)
206+
public virtual TreeChanges Compare(IEnumerable<string> paths = null, bool includeUntracked = false)
206207
{
207208
var comparer = WorkdirToIndex(repo);
208209

209-
using (GitDiffOptions options = BuildOptions(DiffOptions.None, paths))
210+
using (GitDiffOptions options = BuildOptions(includeUntracked ? DiffOptions.IncludeUntracked : DiffOptions.None, paths))
210211
using (DiffListSafeHandle dl = BuildDiffListFromComparer(null, comparer, options))
211212
{
212213
return new TreeChanges(dl);

0 commit comments

Comments
 (0)
0