public virtual void TestSuccess() { // Manually force a delta of an object so we reuse it later. // TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 2); pack.Write((Constants.OBJ_BLOB) << 4 | 1); Deflate(pack, new byte[] { (byte)('a') }); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); a.CopyRawTo(pack); Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); OpenPack(pack); // Verify the only storage of b is our packed delta above. // ObjectDirectory od = (ObjectDirectory)src.ObjectDatabase; NUnit.Framework.Assert.IsTrue(src.HasObject(b), "has b"); NUnit.Framework.Assert.IsFalse(od.FileFor(b).Exists(), "b not loose"); // Now use b but in a different commit than what is hidden. // TestRepository s = new TestRepository <Repository>(src); RevCommit N = s.Commit().Parent(B).Add("q", b).Create(); s.Update(R_MASTER, N); // Push this new content to the remote, doing strict validation. // TransportLocal t = new _TransportLocal_210(this, src, UriOf(dst), dst.Directory); RemoteRefUpdate u = new RemoteRefUpdate(src, R_MASTER, R_MASTER, false, null, null ); // // // src name // dst name // do not force update // local tracking branch // expected id PushResult r; try { t.SetPushThin(true); r = t.Push(PM, Sharpen.Collections.Singleton(u)); } finally { t.Close(); } NUnit.Framework.Assert.IsNotNull(r, "have result"); NUnit.Framework.Assert.IsNull(r.GetAdvertisedRef(R_PRIVATE), "private not advertised" ); NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.OK, u.GetStatus(), "master updated" ); NUnit.Framework.Assert.AreEqual(N, dst.Resolve(R_MASTER)); }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private PushResult TestOneUpdateStatus(RemoteRefUpdate rru, Ref advertisedRef, RemoteRefUpdate.Status expectedStatus, bool?fastForward) { refUpdates.AddItem(rru); if (advertisedRef != null) { advertisedRefs.AddItem(advertisedRef); } PushResult result = ExecutePush(); NUnit.Framework.Assert.AreEqual(expectedStatus, rru.GetStatus()); if (fastForward != null) { NUnit.Framework.Assert.AreEqual(fastForward.Value, rru.IsFastForward()); } return(result); }
public virtual void TestUpdateMixedCases() { RemoteRefUpdate rruOk = new RemoteRefUpdate(db, (string)null, "refs/heads/master" , false, null, null); Ref refToChange = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); RemoteRefUpdate rruReject = new RemoteRefUpdate(db, (string)null, "refs/heads/nonexisting" , false, null, null); refUpdates.AddItem(rruOk); refUpdates.AddItem(rruReject); advertisedRefs.AddItem(refToChange); ExecutePush(); NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.OK, rruOk.GetStatus()); NUnit.Framework.Assert.AreEqual(true, rruOk.IsFastForward()); NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.NON_EXISTING, rruReject.GetStatus ()); }
public void Push (IProgressMonitor monitor, string remote, string remoteBranch) { RemoteConfig remoteConfig = new RemoteConfig (RootRepository.GetConfig (), remote); Transport tp = Transport.Open (RootRepository, remoteConfig); string remoteRef = "refs/heads/" + remoteBranch; RemoteRefUpdate rr = new RemoteRefUpdate (RootRepository, RootRepository.GetBranch (), remoteRef, false, null, null); List<RemoteRefUpdate> list = new List<RemoteRefUpdate> (); list.Add (rr); using (var gm = new GitMonitor (monitor)) tp.Push (gm, list); switch (rr.GetStatus ()) { case RemoteRefUpdate.Status.UP_TO_DATE: monitor.ReportSuccess (GettextCatalog.GetString ("Remote branch is up to date.")); break; case RemoteRefUpdate.Status.REJECTED_NODELETE: monitor.ReportError (GettextCatalog.GetString ("The server is configured to deny deletion of the branch"), null); break; case RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD: monitor.ReportError (GettextCatalog.GetString ("The update is a non-fast-forward update. Merge the remote changes before pushing again."), null); break; case RemoteRefUpdate.Status.OK: monitor.ReportSuccess (GettextCatalog.GetString ("Push operation successfully completed.")); // Update the remote branch ObjectId headId = rr.GetNewObjectId (); RefUpdate updateRef = RootRepository.UpdateRef (Constants.R_REMOTES + remote + "/" + remoteBranch); updateRef.SetNewObjectId(headId); updateRef.Update(); break; default: string msg = rr.GetMessage (); msg = !string.IsNullOrEmpty (msg) ? msg : GettextCatalog.GetString ("Push operation failed"); monitor.ReportError (msg, null); break; } }
public virtual void TestSuccess() { // Manually force a delta of an object so we reuse it later. // TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 2); pack.Write((Constants.OBJ_BLOB) << 4 | 1); Deflate(pack, new byte[] { (byte)('a') }); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); a.CopyRawTo(pack); Deflate(pack, new byte[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked( (int)(0x1)), (byte)('b') }); Digest(pack); OpenPack(pack); // Verify the only storage of b is our packed delta above. // ObjectDirectory od = (ObjectDirectory)src.ObjectDatabase; NUnit.Framework.Assert.IsTrue(src.HasObject(b), "has b"); NUnit.Framework.Assert.IsFalse(od.FileFor(b).Exists(), "b not loose"); // Now use b but in a different commit than what is hidden. // TestRepository s = new TestRepository<Repository>(src); RevCommit N = s.Commit().Parent(B).Add("q", b).Create(); s.Update(R_MASTER, N); // Push this new content to the remote, doing strict validation. // TransportLocal t = new _TransportLocal_210(this, src, UriOf(dst), dst.Directory); RemoteRefUpdate u = new RemoteRefUpdate(src, R_MASTER, R_MASTER, false, null, null ); // // // src name // dst name // do not force update // local tracking branch // expected id PushResult r; try { t.SetPushThin(true); r = t.Push(PM, Sharpen.Collections.Singleton(u)); } finally { t.Close(); } NUnit.Framework.Assert.IsNotNull(r, "have result"); NUnit.Framework.Assert.IsNull(r.GetAdvertisedRef(R_PRIVATE), "private not advertised" ); NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.OK, u.GetStatus(), "master updated" ); NUnit.Framework.Assert.AreEqual(N, dst.Resolve(R_MASTER)); }
/// <exception cref="System.NotSupportedException"></exception> /// <exception cref="NGit.Errors.TransportException"></exception> private PushResult TestOneUpdateStatus(RemoteRefUpdate rru, Ref advertisedRef, RemoteRefUpdate.Status expectedStatus, bool? fastForward) { refUpdates.AddItem(rru); if (advertisedRef != null) { advertisedRefs.AddItem(advertisedRef); } PushResult result = ExecutePush(); NUnit.Framework.Assert.AreEqual(expectedStatus, rru.GetStatus()); if (fastForward != null) { NUnit.Framework.Assert.AreEqual(fastForward.Value, rru.IsFastForward()); } return result; }
public virtual void TestUpdateMixedCases() { RemoteRefUpdate rruOk = new RemoteRefUpdate(db, (string)null, "refs/heads/master" , false, null, null); Ref refToChange = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); RemoteRefUpdate rruReject = new RemoteRefUpdate(db, (string)null, "refs/heads/nonexisting" , false, null, null); refUpdates.AddItem(rruOk); refUpdates.AddItem(rruReject); advertisedRefs.AddItem(refToChange); ExecutePush(); NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.OK, rruOk.GetStatus()); NUnit.Framework.Assert.AreEqual(true, rruOk.IsFastForward()); NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.NON_EXISTING, rruReject.GetStatus ()); }