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); } }
public virtual void TestPushWithRefSpecFromConfig() { 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("HEAD:refs/heads/newbranch")); 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/newbranch" )); }
/// <summary> /// Add a new push RefSpec to this remote. /// </summary> /// <param name="s">the new specification to add.</param> /// <returns>true if the specification was added; false if it already exists.</returns> public bool AddPushRefSpec(RefSpec s) { return(_config.AddPushRefSpec(s)); }