8000 Split Patch and TreeChanges by yorah · Pull Request #512 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

Split Patch and TreeChanges #512

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

Merged
merged 1 commit into from
Oct 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 47 additions & 29 deletions LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ public void CanCompareASimpleTreeAgainstTheWorkDir()
{
SetUpSimpleDiffContext(repo);

TreeChanges changes = repo.Diff.Compare(repo.Head.Tip.Tree,
var changes = repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree,
DiffTargets.WorkingDirectory);
Assert.Equal(1, changes.Modified.Count());

var patch = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree,
DiffTargets.WorkingDirectory);
var expected = new StringBuilder()
.Append("diff --git a/file.txt b/file.txt\n")
.Append("index ce01362..4f125e3 100644\n")
Expand All @@ -56,7 +59,7 @@ public void CanCompareASimpleTreeAgainstTheWorkDir()
.Append("+world\n")
.Append("+!!!\n");

Assert.Equal(expected.ToString(), changes.Patch);
Assert.Equal(expected.ToString(), patch);
}
}

Expand All @@ -67,7 +70,7 @@ public void CanCompareAMoreComplexTreeAgainstTheWorkdir()
{
Tree tree = repo.Head.Tip.Tree;

TreeChanges changes = repo.Diff.Compare(tree, DiffTargets.WorkingDirectory);
var changes = repo.Diff.Compare<TreeChanges>(tree, DiffTargets.WorkingDirectory);
Assert.NotNull(changes);

Assert.Equal(6, changes.Count());
Expand Down Expand Up @@ -103,9 +106,12 @@ public void CanCompareASimpleTreeAgainstTheWorkDirAndTheIndex()
{
SetUpSimpleDiffContext(repo);

TreeChanges changes = repo.Diff.Compare(repo.Head.Tip.Tree,
var changes = repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree,
DiffTargets.Index | DiffTargets.WorkingDirectory);
Assert.Equal(1, changes.Modified.Count());

var patch = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree,
DiffTargets.Index | DiffTargets.WorkingDirectory);
var expected = new StringBuilder()
.Append("diff --git a/file.txt b/file.txt\n")
.Append("index ce01362..4f125e3 100644\n")
Expand All @@ -116,7 +122,7 @@ public void CanCompareASimpleTreeAgainstTheWorkDirAndTheIndex()
.Append("+world\n")
.Append("+!!!\n");

Assert.Equal(expected.ToString(), changes.Patch);
Assert.Equal(expected.ToString(), patch);
}
}

Expand Down Expand Up @@ -158,8 +164,13 @@ public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison()
FileStatus state = repo.Index.RetrieveStatus("file.txt");
Assert.Equal(FileStatus.Removed | FileStatus.Untracked, state);

var wrkDirToIdxToTree = repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree,
DiffTargets.Index | DiffTargets.WorkingDirectory);

Assert.Equal(1, wrkDirToIdxToTree.Deleted.Count());
Assert.Equal(0, wrkDirToIdxToTree.Modified.Count());

TreeChanges wrkDirToIdxToTree = repo.Diff.Compare(repo.Head.Tip.Tree,
var patch = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree,
DiffTargets.Index | DiffTargets.WorkingDirectory);
var expected = new StringBuilder()
.Append("diff --git a/file.txt b/file.txt\n")
Expand All @@ -170,9 +181,15 @@ public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison()
.Append("@@ -1 +0,0 @@\n")
.Append("-hello\n");

Assert.Equal(expected.ToString(), wrkDirToIdxToTree.Patch);
Assert.Equal(expected.ToString(), patch);

TreeChanges wrkDirToTree = repo.Diff.Compare(repo.Head.Tip.Tree,
var wrkDirToTree = repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree,
DiffTargets.WorkingDirectory);

Assert.Equal(0, wrkDirToTree.Deleted.Count());
Assert.Equal(1, wrkDirToTree.Modified.Count());

patch = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree,
DiffTargets.WorkingDirectory);
expected = new StringBuilder()
.Append("diff --git a/file.txt b/file.txt\n")
Expand All @@ -184,7 +201,7 @@ public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison()
.Append("+world\n")
.Append("+!!!\n");

Assert.Equal(expected.ToString(), wrkDirToTree.Patch);
Assert.Equal(expected.ToString(), patch);
}
}

Expand All @@ -207,9 +224,12 @@ public void CanCompareASimpleTreeAgainstTheIndex()
{
SetUpSimpleDiffContext(repo);

TreeChanges changes = repo.Diff.Compare(repo.Head.Tip.Tree,
var changes = repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree,
DiffTargets.Index);
Assert.Equal(1, changes.Modified.Count());

var patch = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree,
DiffTargets.Index);
var expected = new StringBuilder()
.Append("diff --git a/file.txt b/file.txt\n")
.Append("index ce01362..94954ab 100644\n")
Expand All @@ -219,7 +239,7 @@ public void CanCompareASimpleTreeAgainstTheIndex()
.Append(" hello\n")
.Append("+world\n");

Assert.Equal(expected.ToString(), changes.Patch);
Assert.Equal(expected.ToString(), patch);
}
}

Expand Down Expand Up @@ -254,7 +274,7 @@ public void CanCompareAMoreComplexTreeAgainstTheIndex()
{
Tree tree = repo.Head.Tip.Tree;

TreeChanges changes = repo.Diff.Compare(tree, DiffTargets.Index);
var changes = repo.Diff.Compare<TreeChanges>(tree, DiffTargets.Index);
Assert.NotNull(changes);

Assert.Equal(3, changes.Count());
Expand All @@ -281,7 +301,7 @@ public void CanCompareASubsetofTheTreeAgainstTheIndex()
{
Tree tree = repo.Head.Tip.Tree;

TreeChanges changes = repo.Diff.Compare(tree, DiffTargets.Index,
var changes = repo.Diff.Compare<TreeChanges>(tree, DiffTargets.Index,
new[] { "deleted_staged_file.txt", "1/branch_file.txt" });

Assert.NotNull(changes);
Expand All @@ -305,11 +325,11 @@ public void CanCompareASubsetofTheTreeAgainstTheIndexWithLaxExplicitPathsValidat
{
Tree tree = repo.Head.Tip.Tree;

TreeChanges changes = repo.Diff.Compare(tree, DiffTargets.Index,
var changes = repo.Diff.Compare<TreeChanges>(tree, DiffTargets.Index,
new[] { "deleted_staged_file.txt", "1/branch_file.txt", "I-do/not-exist" }, new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false });
AssertCanCompareASubsetOfTheTreeAgainstTheIndex(changes);

changes = repo.Diff.Compare(tree, DiffTargets.Index,
changes = repo.Diff.Compare<TreeChanges>(tree, DiffTargets.Index,
new[] { "deleted_staged_file.txt", "1/branch_file.txt", "I-do/not-exist" });
AssertCanCompareASubsetOfTheTreeAgainstTheIndex(changes);
}
Expand All @@ -322,7 +342,7 @@ public void ComparingASubsetofTheTreeAgainstTheIndexWithStrictExplicitPathsValid
{
Tree tree = repo.Head.Tip.Tree;

Assert.Throws<UnmatchedPathException>(() => repo.Diff.Compare(tree, DiffTargets.Index,
Assert.Throws<UnmatchedPathException>(() => repo.Diff.Compare<TreeChanges>(tree, DiffTargets.Index,
new[] { "deleted_staged_file.txt", "1/branch_file.txt", "I-do/not-exist" }, new ExplicitPathsOptions()));
}
}
Expand Down Expand Up @@ -359,11 +379,10 @@ public void CanCopeWithEndOfFileNewlineChanges()
File.AppendAllText(fullpath, "\n");
repo.Index.Stage("file.txt");

TreeChanges changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index);
var changes = repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree, DiffTargets.Index);
Assert.Equal(1, changes.Modified.Count());
Assert.Equal(1, changes.LinesAdded);
Assert.Equal(1, changes.LinesDeleted);

var patch = repo.Diff.Compare<Patch>(repo.Head.Tip.Tree, DiffTargets.Index);
var expected = new StringBuilder()
.Append("diff --git a/file.txt b/file.txt\n")
.Append("index 2e65efe..7898192 100644\n")
Expand All @@ -374,7 +393,9 @@ public void CanCopeWithEndOfFileNewlineChanges()
.Append("\\ No newline at end of file\n")
.Append("+a\n");

Assert.Equal(expected.ToString(), changes.Patch);
Assert.Equal(expected.ToString(), patch);
Assert.Equal(1, patch.LinesAdded);
Assert.Equal(1, patch.LinesDeleted);
}
}

Expand All @@ -384,11 +405,11 @@ public void ComparingATreeInABareRepositoryAgainstTheWorkDirOrTheIndexThrows()
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<BareRepositoryException>(
() => repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.WorkingDirectory));
() => repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree, DiffTargets.WorkingDirectory));
Assert.Throws<BareRepositoryException>(
() => repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index));
() => repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree, DiffTargets.Index));
Assert.Throws<BareRepositoryException>(
() => repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.WorkingDirectory | DiffTargets.Index));
() => repo.Diff.Compare<TreeChanges>(repo.Head.Tip.Tree, DiffTargets.WorkingDirectory | DiffTargets.Index));
}
}

Expand All @@ -401,14 +422,13 @@ public void CanCompareANullTreeAgainstTheIndex()
{
SetUpSimpleDiffContext(repo);

TreeChanges changes = repo.Diff.Compare(null,
var changes = repo.Diff.Compare<TreeChanges>(null,
DiffTargets.Index);

Assert.Equal(1, changes.Count());
Assert.Equal(1, changes.Added.Count());

Assert.Equal("file.txt", changes.Added.Single().Path);
Assert.Equal(2, changes.Added.Single().LinesAdded);
}
}

Expand All @@ -421,14 +441,13 @@ public void CanCompareANullTreeAgainstTheWorkdir()
{
SetUpSimpleDiffContext(repo);

TreeChanges changes = repo.Diff.Compare(null,
var changes = repo.Diff.Compare<TreeChanges>(null,
DiffTargets.WorkingDirectory);

Assert.Equal(1, changes.Count());
Assert.Equal(1, changes.Added.Count());

Assert.Equal("file.txt", changes.Added.Single().Path);
Assert.Equal(3, changes.Added.Single().LinesAdded);
}
}

Expand All @@ -441,14 +460,13 @@ public void CanCompareANullTreeAgainstTheWorkdirAndTheIndex()
{
SetUpSimpleDiffContext(repo);

TreeChanges changes = repo.Diff.Compare(null,
var changes = repo.Diff.Compare<TreeChanges>(null,
DiffTargets.WorkingDirectory | DiffTargets.Index);

Assert.Equal(1, changes.Count());
Assert.Equal(1, changes.Added.Count());

Assert.Equal("file.txt", changes.Added.Single().Path);
Assert.Equal(3, changes.Added.Single().LinesAdded);
}
}
}
Expand Down
Loading
0