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


C# Git.BranchCreate方法代码示例

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


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

示例1: 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

示例2: CreateBranch

        /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
        /// <exception cref="NGit.Api.Errors.RefAlreadyExistsException"></exception>
        /// <exception cref="NGit.Api.Errors.RefNotFoundException"></exception>
        /// <exception cref="NGit.Api.Errors.InvalidRefNameException"></exception>
        public virtual Ref CreateBranch(Git actGit, string name, bool force, string startPoint
			, CreateBranchCommand.SetupUpstreamMode? mode)
        {
            CreateBranchCommand cmd = actGit.BranchCreate();
            cmd.SetName(name);
            cmd.SetForce(force);
            cmd.SetStartPoint(startPoint);
            cmd.SetUpstreamMode(mode != null ? mode.Value : CreateBranchCommand.SetupUpstreamMode.NOT_SET);
            return cmd.Call();
        }
开发者ID:kenji-tan,项目名称:ngit,代码行数:14,代码来源:BranchCommandTest.cs

示例3: 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

示例4: SetUp

		/// <exception cref="System.Exception"></exception>
		public override void SetUp()
		{
			base.SetUp();
			tr = new TestRepository<Repository>(db);
			git = new Git(db);
			// commit something
			WriteTrashFile("Test.txt", "Hello world");
			git.Add().AddFilepattern("Test.txt").Call();
			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();
			git.Commit().SetMessage("Second commit").Call();
			RevBlob blob = tr.Blob("blob-not-in-master-branch");
			git.Tag().SetName("tag-for-blob").SetObjectId(blob).Call();
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:21,代码来源:CloneCommandTest.cs

示例5: Clone

		public static FileRepository Clone (string targetLocalPath, string url, IProgressMonitor monitor)
		{
			FileRepository repo = Init (targetLocalPath, url, monitor);
			
			// Fetch
			
			string remoteName = "origin";
			string branch = Constants.R_HEADS + "master";
			Transport tn = Transport.Open (repo, remoteName);
			FetchResult r;

			try {
				r = tn.Fetch(new GitMonitor (monitor), null);
			}
			finally {
				tn.Close ();
			}
			
			// Create the master branch
			
			// branch is like 'Constants.R_HEADS + branchName', we need only
			// the 'branchName' part
			String branchName = branch.Substring (Constants.R_HEADS.Length);
			NGit.Api.Git git = new NGit.Api.Git (repo);
			git.BranchCreate ().SetName (branchName).SetUpstreamMode (CreateBranchCommand.SetupUpstreamMode.TRACK).SetStartPoint ("origin/master").Call ();
			
			// Checkout

			DirCache dc = repo.LockDirCache ();
			try {
				RevWalk rw = new RevWalk (repo);
				ObjectId remCommitId = repo.Resolve (remoteName + "/" + branchName);
				RevCommit remCommit = rw.ParseCommit (remCommitId);
				DirCacheCheckout co = new DirCacheCheckout (repo, null, dc, remCommit.Tree);
				co.Checkout ();
			} catch {
				dc.Unlock ();
				throw;
			}
			
			return repo;
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:42,代码来源:GitUtil.cs

示例6: TestResetHard

 public virtual void TestResetHard()
 {
     Git git = new Git(db);
     WriteTrashFile("f", "f()");
     WriteTrashFile("D/g", "g()");
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("inital").Call();
     AssertIndex(Mkmap("f", "f()", "D/g", "g()"));
     git.BranchCreate().SetName("topic").Call();
     WriteTrashFile("f", "f()\nmaster");
     WriteTrashFile("D/g", "g()\ng2()");
     WriteTrashFile("E/h", "h()");
     git.Add().AddFilepattern(".").Call();
     RevCommit master = git.Commit().SetMessage("master-1").Call();
     AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()"));
     CheckoutBranch("refs/heads/topic");
     AssertIndex(Mkmap("f", "f()", "D/g", "g()"));
     WriteTrashFile("f", "f()\nside");
     NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "D/g").Delete());
     WriteTrashFile("G/i", "i()");
     git.Add().AddFilepattern(".").Call();
     git.Add().AddFilepattern(".").SetUpdate(true).Call();
     RevCommit topic = git.Commit().SetMessage("topic-1").Call();
     AssertIndex(Mkmap("f", "f()\nside", "G/i", "i()"));
     WriteTrashFile("untracked", "untracked");
     ResetHard(master);
     AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()"));
     ResetHard(topic);
     AssertIndex(Mkmap("f", "f()\nside", "G/i", "i()"));
     AssertWorkDir(Mkmap("f", "f()\nside", "G/i", "i()", "untracked", "untracked"));
     NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, git.Merge().Include(master
         ).Call().GetMergeStatus());
     NUnit.Framework.Assert.AreEqual("[D/g, mode:100644, stage:1][D/g, mode:100644, stage:3][E/h, mode:100644][G/i, mode:100644][f, mode:100644, stage:1][f, mode:100644, stage:2][f, mode:100644, stage:3]"
         , IndexState(0));
     ResetHard(master);
     AssertIndex(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()"));
     AssertWorkDir(Mkmap("f", "f()\nmaster", "D/g", "g()\ng2()", "E/h", "h()", "untracked"
         , "untracked"));
 }
开发者ID:JamesChan,项目名称:ngit,代码行数:39,代码来源:DirCacheCheckoutTest.cs

示例7: TestPushRefUpdate

		public virtual void TestPushRefUpdate()
		{
			Git git = new Git(db);
			Git git2 = new Git(CreateBareRepository());
			StoredConfig config = git.GetRepository().GetConfig();
			RemoteConfig remoteConfig = new RemoteConfig(config, "test");
			URIish uri = new URIish(git2.GetRepository().Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.AddPushRefSpec(new RefSpec("+refs/heads/*:refs/heads/*"));
			remoteConfig.Update(config);
			config.Save();
			WriteTrashFile("f", "content of f");
			git.Add().AddFilepattern("f").Call();
			RevCommit commit = git.Commit().SetMessage("adding f").Call();
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
				));
			git.Push().SetRemote("test").Call();
			NUnit.Framework.Assert.AreEqual(commit.Id, git2.GetRepository().Resolve("refs/heads/master"
				));
			git.BranchCreate().SetName("refs/heads/test").Call();
			git.Checkout().SetName("refs/heads/test").Call();
			for (int i = 0; i < 6; i++)
			{
				WriteTrashFile("f" + i, "content of f" + i);
				git.Add().AddFilepattern("f" + i).Call();
				commit = git.Commit().SetMessage("adding f" + i).Call();
				git.Push().SetRemote("test").Call();
				git2.GetRepository().GetAllRefs();
				NUnit.Framework.Assert.AreEqual(commit.Id, git2.GetRepository().Resolve("refs/heads/test"
					), "failed to update on attempt " + i);
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:32,代码来源:PushCommandTest.cs

示例8: CommitFile

		/// <summary>
		/// Commit a file with the specified contents on the specified branch,
		/// creating the branch if it didn't exist before.
		/// </summary>
		/// <remarks>
		/// Commit a file with the specified contents on the specified branch,
		/// creating the branch if it didn't exist before.
		/// <p>
		/// It switches back to the original branch after the commit if there was
		/// one.
		/// </remarks>
		/// <param name="filename"></param>
		/// <param name="contents"></param>
		/// <param name="branch"></param>
		/// <returns>the created commit</returns>
		protected internal virtual RevCommit CommitFile(string filename, string contents, 
			string branch)
		{
			try
			{
				Git git = new Git(db);
				string originalBranch = git.GetRepository().GetFullBranch();
				if (git.GetRepository().GetRef(branch) == null)
				{
					git.BranchCreate().SetName(branch).Call();
				}
				git.Checkout().SetName(branch).Call();
				WriteTrashFile(filename, contents);
				git.Add().AddFilepattern(filename).Call();
				RevCommit commit = git.Commit().SetMessage(branch + ": " + filename).Call();
				if (originalBranch != null)
				{
					git.Checkout().SetName(originalBranch).Call();
				}
				return commit;
			}
			catch (IOException e)
			{
				throw new RuntimeException(e);
			}
			catch (GitAPIException e)
			{
				throw new RuntimeException(e);
			}
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:45,代码来源:RepositoryTestCase.cs


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