Permalink
Browse files

Make Diff.Compare consider untracked changes

  • Loading branch information...
mm201 authored and nulltoken committed Mar 11, 2013
1 parent ce5ccef commit e1205a20a284d0f2e8c75f59244aed8840760109
Showing with 17 additions and 2 deletions.
  1. +14 −0 LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs
  2. +3 −2 LibGit2Sharp/Diff.cs
@@ -35,5 +35,19 @@ public void CanCompareTheWorkDirAgainstTheIndex()
Assert.Equal("modified_unstaged_file.txt", changes.Modified.Single().Path);
}
}
+
+ [Fact]
+ public void CanCompareTheWorkDirAgainstTheIndexWithUntrackedFiles()
+ {
+ using (var repo = new Repository(StandardTestRepoPath))
+ {
+ TreeChanges changes = repo.Diff.Compare(null, true);
+
+ Assert.Equal(3, changes.Count());
+ Assert.Equal("deleted_unstaged_file.txt", changes.Deleted.Single().Path);
+ Assert.Equal("modified_unstaged_file.txt", changes.Modified.Single().Path);
+ Assert.Equal("new_untracked_file.txt", changes.Added.Single().Path);
+ }
+ }
}
}
View
@@ -201,12 +201,13 @@ public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnume
/// Show changes between the working directory and the index.
/// </summary>
/// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
+ /// <param name = "includeUntracked">If true, include untracked files from the working dir as additions. Otherwise ignore them.</param>
/// <returns>A <see cref = "TreeChanges"/> containing the changes between the working directory and the index.</returns>
- public virtual TreeChanges Compare(IEnumerable<string> paths = null)
+ public virtual TreeChanges Compare(IEnumerable<string> paths = null, bool includeUntracked = false)
{
var comparer = WorkdirToIndex(repo);
- using (GitDiffOptions options = BuildOptions(DiffOptions.None, paths))
+ using (GitDiffOptions options = BuildOptions(includeUntracked ? DiffOptions.IncludeUntracked : DiffOptions.None, paths))
using (DiffListSafeHandle dl = BuildDiffListFromComparer(null, comparer, options))
{
return new TreeChanges(dl);

0 comments on commit e1205a2

Please sign in to comment.