当前位置: 首页>>代码示例>>C#>>正文


C# Git.Add方法代码示例

本文整理汇总了C#中NGit.Api.Git.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Git.Add方法的具体用法?C# Git.Add怎么用?C# Git.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NGit.Api.Git的用法示例。


在下文中一共展示了Git.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResolveUnnamedCurrentBranchCommits

		public virtual void ResolveUnnamedCurrentBranchCommits()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c1 = git.Commit().SetMessage("create file").Call();
			WriteTrashFile("file.txt", "content2");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c2 = git.Commit().SetMessage("edit file").Call();
			NUnit.Framework.Assert.AreEqual(c2, db.Resolve("[email protected]{0}"));
			NUnit.Framework.Assert.AreEqual(c1, db.Resolve("[email protected]{1}"));
			git.Checkout().SetCreateBranch(true).SetName("newbranch").SetStartPoint(c1).Call(
				);
			// same as current branch, e.g. master
			NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{0}"));
			try
			{
				NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{1}"));
				NUnit.Framework.Assert.Fail();
			}
			catch (RevisionSyntaxException e)
			{
				// Looking at wrong ref, e.g HEAD
				NUnit.Framework.Assert.IsNotNull(e);
			}
			// detached head, read HEAD reflog
			git.Checkout().SetName(c2.GetName()).Call();
			NUnit.Framework.Assert.AreEqual(c2, db.Resolve("@{0}"));
			NUnit.Framework.Assert.AreEqual(c1, db.Resolve("@{1}"));
			NUnit.Framework.Assert.AreEqual(c2, db.Resolve("@{2}"));
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:31,代码来源:ReflogResolveTest.cs

示例2: FailingPathsShouldNotResultInOKReturnValue

 public virtual void FailingPathsShouldNotResultInOKReturnValue()
 {
     FilePath folder1 = new FilePath(db.WorkTree, "folder1");
     FileUtils.Mkdir(folder1);
     FilePath file = new FilePath(folder1, "file1.txt");
     Write(file, "folder1--file1.txt");
     file = new FilePath(folder1, "file2.txt");
     Write(file, "folder1--file2.txt");
     Git git = new Git(db);
     git.Add().AddFilepattern(folder1.GetName()).Call();
     RevCommit @base = git.Commit().SetMessage("adding folder").Call();
     RecursiveDelete(folder1);
     git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
         Call();
     RevCommit other = git.Commit().SetMessage("removing folders on 'other'").Call();
     git.Checkout().SetName(@base.Name).Call();
     file = new FilePath(db.WorkTree, "unrelated.txt");
     Write(file, "unrelated");
     git.Add().AddFilepattern("unrelated").Call();
     RevCommit head = git.Commit().SetMessage("Adding another file").Call();
     // Untracked file to cause failing path for delete() of folder1
     file = new FilePath(folder1, "file3.txt");
     Write(file, "folder1--file3.txt");
     ResolveMerger merger = new ResolveMerger(db, false);
     merger.SetCommitNames(new string[] { "BASE", "HEAD", "other" });
     merger.SetWorkingTreeIterator(new FileTreeIterator(db));
     bool ok = merger.Merge(head.Id, other.Id);
     NUnit.Framework.Assert.IsFalse(merger.GetFailingPaths().IsEmpty());
     NUnit.Framework.Assert.IsFalse(ok);
 }
开发者ID:dprothero,项目名称:ngit,代码行数:30,代码来源:ResolveMergerTest.cs

示例3: TestRevert

		public virtual void TestRevert()
		{
			Git git = new Git(db);
			WriteTrashFile("a", "first line\nsec. line\nthird line\n");
			git.Add().AddFilepattern("a").Call();
			git.Commit().SetMessage("create a").Call();
			WriteTrashFile("b", "content\n");
			git.Add().AddFilepattern("b").Call();
			git.Commit().SetMessage("create b").Call();
			WriteTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
			git.Add().AddFilepattern("a").Call();
			git.Commit().SetMessage("enlarged a").Call();
			WriteTrashFile("a", "first line\nsecond line\nthird line\nfourth line\n");
			git.Add().AddFilepattern("a").Call();
			RevCommit fixingA = git.Commit().SetMessage("fixed a").Call();
			WriteTrashFile("b", "first line\n");
			git.Add().AddFilepattern("b").Call();
			git.Commit().SetMessage("fixed b").Call();
			git.Revert().Include(fixingA).Call();
			NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "b").Exists());
			CheckFile(new FilePath(db.WorkTree, "a"), "first line\nsec. line\nthird line\nfourth line\n"
				);
			Iterator<RevCommit> history = git.Log().Call().Iterator();
			RevCommit revertCommit = history.Next();
			string expectedMessage = "Revert \"fixed a\"\n\n" + "This reverts commit " + fixingA
				.Id.GetName() + ".\n";
			NUnit.Framework.Assert.AreEqual(expectedMessage, revertCommit.GetFullMessage());
			NUnit.Framework.Assert.AreEqual("fixed b", history.Next().GetFullMessage());
			NUnit.Framework.Assert.AreEqual("fixed a", history.Next().GetFullMessage());
			NUnit.Framework.Assert.AreEqual("enlarged a", history.Next().GetFullMessage());
			NUnit.Framework.Assert.AreEqual("create b", history.Next().GetFullMessage());
			NUnit.Framework.Assert.AreEqual("create a", history.Next().GetFullMessage());
			NUnit.Framework.Assert.IsFalse(history.HasNext());
		}
开发者ID:shoff,项目名称:ngit,代码行数:34,代码来源:RevertCommandTest.cs

示例4: TestCherryPick

		public virtual void TestCherryPick()
		{
			Git git = new Git(db);
			WriteTrashFile("a", "first line\nsec. line\nthird line\n");
			git.Add().AddFilepattern("a").Call();
			RevCommit firstCommit = git.Commit().SetMessage("create a").Call();
			WriteTrashFile("b", "content\n");
			git.Add().AddFilepattern("b").Call();
			git.Commit().SetMessage("create b").Call();
			WriteTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
			git.Add().AddFilepattern("a").Call();
			git.Commit().SetMessage("enlarged a").Call();
			WriteTrashFile("a", "first line\nsecond line\nthird line\nfourth line\n");
			git.Add().AddFilepattern("a").Call();
			RevCommit fixingA = git.Commit().SetMessage("fixed a").Call();
			git.BranchCreate().SetName("side").SetStartPoint(firstCommit).Call();
			CheckoutBranch("refs/heads/side");
			WriteTrashFile("a", "first line\nsec. line\nthird line\nfeature++\n");
			git.Add().AddFilepattern("a").Call();
			git.Commit().SetMessage("enhanced a").Call();
			git.CherryPick().Include(fixingA).Call();
			NUnit.Framework.Assert.IsFalse(new FilePath(db.WorkTree, "b").Exists());
			CheckFile(new FilePath(db.WorkTree, "a"), "first line\nsecond line\nthird line\nfeature++\n"
				);
			Iterator<RevCommit> history = git.Log().Call().Iterator();
			NUnit.Framework.Assert.AreEqual("fixed a", history.Next().GetFullMessage());
			NUnit.Framework.Assert.AreEqual("enhanced a", history.Next().GetFullMessage());
			NUnit.Framework.Assert.AreEqual("create a", history.Next().GetFullMessage());
			NUnit.Framework.Assert.IsFalse(history.HasNext());
		}
开发者ID:shoff,项目名称:ngit,代码行数:30,代码来源:CherryPickCommandTest.cs

示例5: TestLastModifiedTimes

		public virtual void TestLastModifiedTimes()
		{
			Git git = new Git(db);
			string path = "file";
			WriteTrashFile(path, "content");
			string path2 = "file2";
			WriteTrashFile(path2, "content2");
			git.Add().AddFilepattern(path).Call();
			git.Add().AddFilepattern(path2).Call();
			git.Commit().SetMessage("commit").Call();
			DirCache dc = db.ReadDirCache();
			DirCacheEntry entry = dc.GetEntry(path);
			DirCacheEntry entry2 = dc.GetEntry(path);
			NUnit.Framework.Assert.IsTrue(entry.LastModified != 0, "last modified shall not be zero!"
				);
			NUnit.Framework.Assert.IsTrue(entry2.LastModified != 0, "last modified shall not be zero!"
				);
			WriteTrashFile(path, "new content");
			git.Add().AddFilepattern(path).Call();
			git.Commit().SetMessage("commit2").Call();
			dc = db.ReadDirCache();
			entry = dc.GetEntry(path);
			entry2 = dc.GetEntry(path);
			NUnit.Framework.Assert.IsTrue(entry.LastModified != 0, "last modified shall not be zero!"
				);
			NUnit.Framework.Assert.IsTrue(entry2.LastModified != 0, "last modified shall not be zero!"
				);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:28,代码来源:IndexModificationTimesTest.cs

示例6: ResolveMasterCommits

		public virtual void ResolveMasterCommits()
		{
			Git git = new Git(db);
			WriteTrashFile("file.txt", "content");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c1 = git.Commit().SetMessage("create file").Call();
			WriteTrashFile("file.txt", "content2");
			git.Add().AddFilepattern("file.txt").Call();
			RevCommit c2 = git.Commit().SetMessage("edit file").Call();
			NUnit.Framework.Assert.AreEqual(c2, db.Resolve("[email protected]{0}"));
			NUnit.Framework.Assert.AreEqual(c1, db.Resolve("[email protected]{1}"));
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:12,代码来源:ReflogResolveTest.cs

示例7: SetUp

 public override void SetUp()
 {
     base.SetUp();
     dbTarget = CreateWorkRepository();
     source = new Git(db);
     target = new Git(dbTarget);
     // put some file in the source repo
     sourceFile = new FilePath(db.WorkTree, "SomeFile.txt");
     WriteToFile(sourceFile, "Hello world");
     // and commit it
     source.Add().AddFilepattern("SomeFile.txt").Call();
     source.Commit().SetMessage("Initial commit for source").Call();
     // configure the target repo to connect to the source via "origin"
     StoredConfig targetConfig = ((FileBasedConfig)dbTarget.GetConfig());
     targetConfig.SetString("branch", "master", "remote", "origin");
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     RemoteConfig config = new RemoteConfig(targetConfig, "origin");
     config.AddURI(new URIish(source.GetRepository().WorkTree.GetPath()));
     config.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
     config.Update(targetConfig);
     targetConfig.Save();
     targetFile = new FilePath(dbTarget.WorkTree, "SomeFile.txt");
     // make sure we have the same content
     target.Pull().Call();
     target.Checkout().SetStartPoint("refs/remotes/origin/master").SetName("master").Call
         ();
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     targetConfig.SetBoolean("branch", "master", "rebase", true);
     targetConfig.Save();
     AssertFileContentsEqual(targetFile, "Hello world");
 }
开发者ID:nnieslan,项目名称:ngit,代码行数:31,代码来源:PullCommandWithRebaseTest.cs

示例8: IdOffset

 public virtual void IdOffset()
 {
     Git git = new Git(db);
     WriteTrashFile("fileAinfsonly", "A");
     FilePath fileBinindex = WriteTrashFile("fileBinindex", "B");
     FsTick(fileBinindex);
     git.Add().AddFilepattern("fileBinindex").Call();
     WriteTrashFile("fileCinfsonly", "C");
     TreeWalk tw = new TreeWalk(db);
     DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache());
     FileTreeIterator workTreeIter = new FileTreeIterator(db);
     tw.AddTree(indexIter);
     tw.AddTree(workTreeIter);
     workTreeIter.SetDirCacheIterator(tw, 0);
     AssertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw);
     AssertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw);
     AssertEntry("0000000000000000000000000000000000000000", "a", tw);
     AssertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw);
     // The reason for adding this test. Check that the id is correct for
     // mixed
     AssertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220", "fileAinfsonly", tw);
     AssertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex", tw);
     AssertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c", "fileCinfsonly", tw);
     NUnit.Framework.Assert.IsFalse(tw.Next());
 }
开发者ID:red-gate,项目名称:ngit,代码行数:25,代码来源:FileTreeIteratorTest.cs

示例9: CommitAfterSquashMerge

 public virtual void CommitAfterSquashMerge()
 {
     Git git = new Git(db);
     WriteTrashFile("file1", "file1");
     git.Add().AddFilepattern("file1").Call();
     RevCommit first = git.Commit().SetMessage("initial commit").Call();
     NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
     CreateBranch(first, "refs/heads/branch1");
     CheckoutBranch("refs/heads/branch1");
     WriteTrashFile("file2", "file2");
     git.Add().AddFilepattern("file2").Call();
     git.Commit().SetMessage("second commit").Call();
     NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
     CheckoutBranch("refs/heads/master");
     MergeCommandResult result = git.Merge().Include(db.GetRef("branch1")).SetSquash(true
         ).Call();
     NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
     NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
     NUnit.Framework.Assert.AreEqual(MergeStatus.FAST_FORWARD_SQUASHED, result.GetMergeStatus
         ());
     // comment not set, should be inferred from SQUASH_MSG
     RevCommit squashedCommit = git.Commit().Call();
     NUnit.Framework.Assert.AreEqual(1, squashedCommit.ParentCount);
     NUnit.Framework.Assert.IsNull(db.ReadSquashCommitMsg());
     NUnit.Framework.Assert.AreEqual("commit: Squashed commit of the following:", db.GetReflogReader
         (Constants.HEAD).GetLastEntry().GetComment());
     NUnit.Framework.Assert.AreEqual("commit: Squashed commit of the following:", db.GetReflogReader
         (db.GetBranch()).GetLastEntry().GetComment());
 }
开发者ID:OrangeCloudNetworks,项目名称:ngit,代码行数:29,代码来源:CommitCommandTest.cs

示例10: TestAddUnstagedChanges

 public virtual void TestAddUnstagedChanges()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     Git git = new Git(db);
     git.Add().AddFilepattern("a.txt").Call();
     RevCommit commit = git.Commit().SetMessage("initial commit").Call();
     TreeWalk tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
         (0).GetName());
     writer = new PrintWriter(file);
     writer.Write("content2");
     writer.Close();
     commit = git.Commit().SetMessage("second commit").Call();
     tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
         (0).GetName());
     commit = git.Commit().SetAll(true).SetMessage("third commit").SetAll(true).Call();
     tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("db00fd65b218578127ea51f3dffac701f12f486a", tw.GetObjectId
         (0).GetName());
 }
开发者ID:dprothero,项目名称:ngit,代码行数:25,代码来源:CommitAndLogCommandTests.cs

示例11: SetUp

		public override void SetUp()
		{
			base.SetUp();
			git = new Git(db);
			WriteTrashFile(FILE1, "1");
			WriteTrashFile(FILE2, "a");
			git.Add().AddFilepattern(FILE1).AddFilepattern(FILE2).Call();
			initialCommit = git.Commit().SetMessage("Initial commit").Call();
			WriteTrashFile(FILE1, "2");
			WriteTrashFile(FILE2, "b");
			git.Add().AddFilepattern(FILE1).AddFilepattern(FILE2).Call();
			secondCommit = git.Commit().SetMessage("Second commit").Call();
			WriteTrashFile(FILE1, "3");
			WriteTrashFile(FILE2, "c");
			git.Add().AddFilepattern(FILE1).AddFilepattern(FILE2).Call();
			git.Commit().SetMessage("Third commit").Call();
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:17,代码来源:PathCheckoutCommandTest.cs

示例12: SetUp

		public override void SetUp()
		{
			base.SetUp();
			git = new Git(db);
			// commit something
			WriteTrashFile("Test.txt", "Hello world");
			git.Add().AddFilepattern("Test.txt").Call();
			initialCommit = git.Commit().SetMessage("Initial commit").Call();
			// create a master branch and switch to it
			git.BranchCreate().SetName("test").Call();
			RefUpdate rup = db.UpdateRef(Constants.HEAD);
			rup.Link("refs/heads/test");
			// commit something on the test branch
			WriteTrashFile("Test.txt", "Some change");
			git.Add().AddFilepattern("Test.txt").Call();
			secondCommit = git.Commit().SetMessage("Second commit").Call();
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:17,代码来源:CheckoutCommandTest.cs

示例13: SetUp

		public override void SetUp()
		{
			base.SetUp();
			git = Git.Wrap(db);
			committedFile = WriteTrashFile(PATH, "content");
			git.Add().AddFilepattern(PATH).Call();
			head = git.Commit().SetMessage("add file").Call();
			NUnit.Framework.Assert.IsNotNull(head);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:9,代码来源:StashApplyCommandTest.cs

示例14: SetUp

		public override void SetUp()
		{
			base.SetUp();
			git = new Git(db);
			// commit something
			WriteTrashFile(FILE, "Hello world");
			git.Add().AddFilepattern(FILE).Call();
			git.Commit().SetMessage("Initial commit").Call();
		}
开发者ID:shoff,项目名称:ngit,代码行数:9,代码来源:RmCommandTest.cs

示例15: SetUp

		public override void SetUp()
		{
			base.SetUp();
			git = new Git(db);
			// checkout master
			git.Commit().SetMessage("initial commit").Call();
			// commit something
			WriteTrashFile("Test.txt", "Hello world");
			git.Add().AddFilepattern("Test.txt").Call();
			initialCommit = git.Commit().SetMessage("Initial commit").Call();
			WriteTrashFile("Test.txt", "Some change");
			git.Add().AddFilepattern("Test.txt").Call();
			secondCommit = git.Commit().SetMessage("Second commit").Call();
			// create a master branch
			RefUpdate rup = db.UpdateRef("refs/heads/master");
			rup.SetNewObjectId(initialCommit.Id);
			rup.SetForceUpdate(true);
			rup.Update();
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:19,代码来源:BranchCommandTest.cs


注:本文中的NGit.Api.Git.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。