本文整理汇总了C#中NGit.Api.Git.Diff方法的典型用法代码示例。如果您正苦于以下问题:C# Git.Diff方法的具体用法?C# Git.Diff怎么用?C# Git.Diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NGit.Api.Git
的用法示例。
在下文中一共展示了Git.Diff方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDiffModified
public virtual void TestDiffModified()
{
Write(new FilePath(db.WorkTree, "test.txt"), "test");
FilePath folder = new FilePath(db.WorkTree, "folder");
folder.Mkdir();
Write(new FilePath(folder, "folder.txt"), "folder");
Git git = new Git(db);
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("Initial commit").Call();
Write(new FilePath(folder, "folder.txt"), "folder change");
OutputStream @out = new ByteArrayOutputStream();
IList<DiffEntry> entries = git.Diff().SetOutputStream(@out).Call();
NUnit.Framework.Assert.AreEqual(1, entries.Count);
NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, entries[0].GetChangeType
());
NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetOldPath());
NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetNewPath());
string actual = @out.ToString();
string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
+ "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
"-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
}
示例2: TestDiffWithPrefixes
public virtual void TestDiffWithPrefixes()
{
Write(new FilePath(db.WorkTree, "test.txt"), "test");
Git git = new Git(db);
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("Initial commit").Call();
Write(new FilePath(db.WorkTree, "test.txt"), "test change");
OutputStream @out = new ByteArrayOutputStream();
git.Diff().SetOutputStream(@out).SetSourcePrefix("old/").SetDestinationPrefix("new/"
).Call();
string actual = @out.ToString();
string expected = "diff --git old/test.txt new/test.txt\n" + "index 30d74d2..4dba797 100644\n"
+ "--- old/test.txt\n" + "+++ new/test.txt\n" + "@@ -1 +1 @@\n" + "-test\n" + "\\ No newline at end of file\n"
+ "+test change\n" + "\\ No newline at end of file\n";
NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
}
示例3: TestDiffWithNegativeLineCount
public virtual void TestDiffWithNegativeLineCount()
{
Write(new FilePath(db.WorkTree, "test.txt"), "0\n1\n2\n3\n4\n5\n6\n7\n8\n9");
Git git = new Git(db);
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("Initial commit").Call();
Write(new FilePath(db.WorkTree, "test.txt"), "0\n1\n2\n3\n4a\n5\n6\n7\n8\n9");
OutputStream @out = new ByteArrayOutputStream();
git.Diff().SetOutputStream(@out).SetContextLines(1).Call();
string actual = @out.ToString();
string expected = "diff --git a/test.txt b/test.txt\n" + "index f55b5c9..c5ec8fd 100644\n"
+ "--- a/test.txt\n" + "+++ b/test.txt\n" + "@@ -4,3 +4,3 @@\n" + " 3\n" + "-4\n"
+ "+4a\n" + " 5\n";
NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
}
示例4: TestDiffTwoCommits
public virtual void TestDiffTwoCommits()
{
Write(new FilePath(db.WorkTree, "test.txt"), "test");
FilePath folder = new FilePath(db.WorkTree, "folder");
folder.Mkdir();
Write(new FilePath(folder, "folder.txt"), "folder");
Git git = new Git(db);
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("Initial commit").Call();
Write(new FilePath(folder, "folder.txt"), "folder change");
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("second commit").Call();
Write(new FilePath(folder, "folder.txt"), "second folder change");
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("third commit").Call();
// bad filter
DiffCommand diff = git.Diff().SetShowNameAndStatusOnly(true).SetPathFilter(PathFilter
.Create("test.txt")).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree(GetTreeIterator
("HEAD^"));
IList<DiffEntry> entries = diff.Call();
NUnit.Framework.Assert.AreEqual(0, entries.Count);
// no filter, two commits
OutputStream @out = new ByteArrayOutputStream();
diff = git.Diff().SetOutputStream(@out).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree
(GetTreeIterator("HEAD^"));
entries = diff.Call();
NUnit.Framework.Assert.AreEqual(1, entries.Count);
NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, entries[0].GetChangeType
());
NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetOldPath());
NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetNewPath());
string actual = @out.ToString();
string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
+ "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
"-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
}
示例5: TestNoOutputStreamSet
public virtual void TestNoOutputStreamSet()
{
FilePath file = WriteTrashFile("test.txt", "a");
NUnit.Framework.Assert.IsTrue(file.SetLastModified(file.LastModified() - 5000));
Git git = new Git(db);
git.Add().AddFilepattern(".").Call();
Write(file, "b");
IList<DiffEntry> diffs = git.Diff().Call();
NUnit.Framework.Assert.IsNotNull(diffs);
NUnit.Framework.Assert.AreEqual(1, diffs.Count);
DiffEntry diff = diffs[0];
NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, diff.GetChangeType()
);
NUnit.Framework.Assert.AreEqual("test.txt", diff.GetOldPath());
NUnit.Framework.Assert.AreEqual("test.txt", diff.GetNewPath());
}