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


C# Git.Push方法代碼示例

本文整理匯總了C#中NGit.Api.Git.Push方法的典型用法代碼示例。如果您正苦於以下問題:C# Git.Push方法的具體用法?C# Git.Push怎麽用?C# Git.Push使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NGit.Api.Git的用法示例。


在下文中一共展示了Git.Push方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Push

		public ICommandResponse Push (string path)
		{
			Git git = new Git(new FileRepository(ToGitDirString(path)));
			Iterable<PushResult> pushResults = git.Push().Call();
			ICommandResponse result = new NGitPushResultAdapter(pushResults);
			return result;
		}
開發者ID:draptik,項目名稱:RepoSync,代碼行數:7,代碼來源:NGitStrategy.cs

示例2: TestTrackingUpdate

		public virtual void TestTrackingUpdate()
		{
			Repository db2 = CreateBareRepository();
			string remote = "origin";
			string branch = "refs/heads/master";
			string trackingBranch = "refs/remotes/" + remote + "/master";
			Git git = new Git(db);
			RevCommit commit1 = git.Commit().SetMessage("Initial commit").Call();
			RefUpdate branchRefUpdate = db.UpdateRef(branch);
			branchRefUpdate.SetNewObjectId(commit1.Id);
			branchRefUpdate.Update();
			RefUpdate trackingBranchRefUpdate = db.UpdateRef(trackingBranch);
			trackingBranchRefUpdate.SetNewObjectId(commit1.Id);
			trackingBranchRefUpdate.Update();
			StoredConfig config = ((FileBasedConfig)db.GetConfig());
			RemoteConfig remoteConfig = new RemoteConfig(config, remote);
			URIish uri = new URIish(db2.Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + remote +
				 "/*"));
			remoteConfig.Update(config);
			config.Save();
			RevCommit commit2 = git.Commit().SetMessage("Commit to push").Call();
			RefSpec spec = new RefSpec(branch + ":" + branch);
			Iterable<PushResult> resultIterable = git.Push().SetRemote(remote).SetRefSpecs(spec
				).Call();
			PushResult result = resultIterable.Iterator().Next();
			TrackingRefUpdate trackingRefUpdate = result.GetTrackingRefUpdate(trackingBranch);
			NUnit.Framework.Assert.IsNotNull(trackingRefUpdate);
			NUnit.Framework.Assert.AreEqual(trackingBranch, trackingRefUpdate.GetLocalName());
			NUnit.Framework.Assert.AreEqual(branch, trackingRefUpdate.GetRemoteName());
			NUnit.Framework.Assert.AreEqual(commit2.Id, trackingRefUpdate.GetNewObjectId());
			NUnit.Framework.Assert.AreEqual(commit2.Id, db.Resolve(trackingBranch));
			NUnit.Framework.Assert.AreEqual(commit2.Id, db2.Resolve(branch));
		}
開發者ID:LunarLanding,項目名稱:ngit,代碼行數:35,代碼來源:PushCommandTest.cs

示例3: TestPushWithoutPushRefSpec

		public virtual void TestPushWithoutPushRefSpec()
		{
			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.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
			remoteConfig.Update(config);
			config.Save();
			WriteTrashFile("f", "content of f");
			git.Add().AddFilepattern("f").Call();
			RevCommit commit = git.Commit().SetMessage("adding f").Call();
			git.Checkout().SetName("not-pushed").SetCreateBranch(true).Call();
			git.Checkout().SetName("branchtopush").SetCreateBranch(true).Call();
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/branchtopush"
				));
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/not-pushed"
				));
			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/branchtopush"
				));
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/not-pushed"
				));
			NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
				));
		}
開發者ID:LunarLanding,項目名稱:ngit,代碼行數:30,代碼來源:PushCommandTest.cs

示例4: TestPush

		public virtual void TestPush()
		{
			// create other repository
			Repository db2 = CreateWorkRepository();
			// setup the first repository
			StoredConfig config = ((FileBasedConfig)db.GetConfig());
			RemoteConfig remoteConfig = new RemoteConfig(config, "test");
			URIish uri = new URIish(db2.Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.Update(config);
			config.Save();
			Git git1 = new Git(db);
			// create some refs via commits and tag
			RevCommit commit = git1.Commit().SetMessage("initial commit").Call();
			Ref tagRef = git1.Tag().SetName("tag").Call();
			try
			{
				db2.Resolve(commit.Id.GetName() + "^{commit}");
				NUnit.Framework.Assert.Fail("id shouldn't exist yet");
			}
			catch (MissingObjectException)
			{
			}
			// we should get here
			RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
			git1.Push().SetRemote("test").SetRefSpecs(spec).Call();
			NUnit.Framework.Assert.AreEqual(commit.Id, db2.Resolve(commit.Id.GetName() + "^{commit}"
				));
			NUnit.Framework.Assert.AreEqual(tagRef.GetObjectId(), db2.Resolve(tagRef.GetObjectId
				().GetName()));
		}
開發者ID:LunarLanding,項目名稱:ngit,代碼行數:31,代碼來源:PushCommandTest.cs

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


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