當前位置: 首頁>>代碼示例>>C#>>正文


C# Git.Diff方法代碼示例

本文整理匯總了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);
		}
開發者ID:LunarLanding,項目名稱:ngit,代碼行數:23,代碼來源:DiffCommandTest.cs

示例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);
 }
開發者ID:JamesChan,項目名稱:ngit,代碼行數:16,代碼來源:DiffCommandTest.cs

示例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);
 }
開發者ID:JamesChan,項目名稱:ngit,代碼行數:15,代碼來源:DiffCommandTest.cs

示例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);
 }
開發者ID:JamesChan,項目名稱:ngit,代碼行數:37,代碼來源:DiffCommandTest.cs

示例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());
		}
開發者ID:LunarLanding,項目名稱:ngit,代碼行數:16,代碼來源:DiffCommandTest.cs


注:本文中的NGit.Api.Git.Diff方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。