Navigation Menu

Skip to content

Commit

Permalink
Make Diff.Compare consider untracked changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mm201 authored and nulltoken committed Mar 11, 2013
1 parent ce5ccef commit e1205a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 14 additions & 0 deletions LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs
Expand Up @@ -35,5 +35,19 @@ public void CanCompareTheWorkDirAgainstTheIndex()
Assert.Equal("modified_unstaged_file.txt", changes.Modified.Single().Path); 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);
}
}
} }
} }
5 changes: 3 additions & 2 deletions LibGit2Sharp/Diff.cs
Expand Up @@ -201,12 +201,13 @@ public virtual TreeChanges Compare(Tree oldTree, DiffTargets diffTargets, IEnume
/// Show changes between the working directory and the index. /// Show changes between the working directory and the index.
/// </summary> /// </summary>
/// <param name = "paths">The list of paths (either files or directories) that should be compared.</param> /// <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> /// <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); 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)) using (DiffListSafeHandle dl = BuildDiffListFromComparer(null, comparer, options))
{ {
return new TreeChanges(dl); return new TreeChanges(dl);
Expand Down

0 comments on commit e1205a2

Please sign in to comment.