8000 Diff.Compare overload to include untracked changes by mm201 · Pull Request #359 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

Diff.Compare overload to include untracked changes #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Load 8000 ing
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added Diff.Compare overload to retrieve untracked changes from the wo…
…rking dir.
  • Loading branch information
mm201 committed Mar 11, 2013
commit 51732f1845fd4c03771b103ecdaf642764b10763
14 changes: 14 additions & 0 deletions LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
5 changes: 3 additions & 2 deletions LibGit2Sharp/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,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);
Expand Down
0