public virtual void TestUpdateDeleteNonExisting() { RemoteRefUpdate rru = new RemoteRefUpdate(db, (string)null, "refs/heads/master", false, null, null); TestOneUpdateStatus(rru, null, RemoteRefUpdate.Status.NON_EXISTING, null); }
public virtual void TestUpdateCreateRef() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef" , "refs/heads/master", false, null, null); TestOneUpdateStatus(rru, null, RemoteRefUpdate.Status.OK, true); }
public virtual void TestUpdateFastForward() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", false, null, null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); TestOneUpdateStatus(rru, @ref, RemoteRefUpdate.Status.OK, true); }
private void UpdateSuccessStatus (RemoteRefUpdate.Status status) { if (status == RemoteRefUpdate.Status.OK || status == RemoteRefUpdate.Status.UP_TO_DATE) { Success = true; } else { Success = false; } }
public virtual void TestUpdateUpToDate() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", false, null, null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); TestOneUpdateStatus(rru, @ref, RemoteRefUpdate.Status.UP_TO_DATE, null); }
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)); }
public virtual void TestUpdateNonFastForwardUnknownObject() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", false, null, null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("0000000000000000000000000000000000000001")); TestOneUpdateStatus(rru, @ref, RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD, null ); }
public virtual void TestUpdateUnexpectedRemoteVsForce() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", true, null, ObjectId.FromString("0000000000000000000000000000000000000001" )); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); TestOneUpdateStatus(rru, @ref, RemoteRefUpdate.Status.REJECTED_REMOTE_CHANGED, null ); }
public virtual void TestUpdateRejectedByConnection() { connectionUpdateStatus = RemoteRefUpdate.Status.REJECTED_OTHER_REASON; RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", false, null, null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); TestOneUpdateStatus(rru, @ref, RemoteRefUpdate.Status.REJECTED_OTHER_REASON, null ); }
public virtual void TestTrackingRefUpdateOnReject() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef" , "refs/heads/master", false, null, null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); PushResult result = TestOneUpdateStatus(rru, @ref, RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD , null); NUnit.Framework.Assert.IsTrue(result.GetTrackingRefUpdates().IsEmpty()); }
public virtual void TestTrackingRefUpdateDisabled() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", false, null, null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); refUpdates.AddItem(rru); advertisedRefs.AddItem(@ref); PushResult result = ExecutePush(); NUnit.Framework.Assert.IsTrue(result.GetTrackingRefUpdates().IsEmpty()); }
private void UpdateCommand(RemoteRefUpdate u) { try { dest.WriteRef(u.GetRemoteName(), u.GetNewObjectId()); newRefs.Put(u.GetRemoteName(), new ObjectIdRef.Unpeeled(RefStorage.LOOSE, u.GetRemoteName (), u.GetNewObjectId())); u.SetStatus(RemoteRefUpdate.Status.OK); } catch (IOException e) { u.SetStatus(RemoteRefUpdate.Status.REJECTED_OTHER_REASON); u.SetMessage(e.Message); } }
public virtual void TestTrackingRefUpdateEnabled() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", false, "refs/remotes/test/master", null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); refUpdates.AddItem(rru); advertisedRefs.AddItem(@ref); PushResult result = ExecutePush(); TrackingRefUpdate tru = result.GetTrackingRefUpdate("refs/remotes/test/master"); NUnit.Framework.Assert.IsNotNull(tru); NUnit.Framework.Assert.AreEqual("refs/remotes/test/master", tru.GetLocalName()); NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, tru.GetResult()); }
public virtual void TestFindRemoteRefUpdatesNoWildcardNoTracking() { transport = NGit.Transport.Transport.Open(db, remoteConfig); ICollection <RemoteRefUpdate> result = transport.FindRemoteRefUpdatesFor(Collections .NCopies(1, new RefSpec("refs/heads/master:refs/heads/x"))); NUnit.Framework.Assert.AreEqual(1, result.Count); RemoteRefUpdate rru = result.Iterator().Next(); NUnit.Framework.Assert.IsNull(rru.GetExpectedOldObjectId()); NUnit.Framework.Assert.IsFalse(rru.IsForceUpdate()); NUnit.Framework.Assert.AreEqual("refs/heads/master", rru.GetSrcRef()); NUnit.Framework.Assert.AreEqual(db.Resolve("refs/heads/master"), rru.GetNewObjectId ()); NUnit.Framework.Assert.AreEqual("refs/heads/x", rru.GetRemoteName()); }
/// <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 ()); }
// Ignore the deletion failure. We probably are // already failing and were just trying to pick // up after ourselves. private void DeleteCommand(RemoteRefUpdate u) { Ref r = Sharpen.Collections.Remove(newRefs, u.GetRemoteName()); if (r == null) { // Already gone. // u.SetStatus(RemoteRefUpdate.Status.OK); return; } if (r.GetStorage().IsPacked()) { packedRefUpdates.AddItem(u); } if (r.GetStorage().IsLoose()) { try { dest.DeleteRef(u.GetRemoteName()); u.SetStatus(RemoteRefUpdate.Status.OK); } catch (IOException e) { u.SetStatus(RemoteRefUpdate.Status.REJECTED_OTHER_REASON); u.SetMessage(e.Message); } } try { dest.DeleteRefLog(u.GetRemoteName()); } catch (IOException e) { u.SetStatus(RemoteRefUpdate.Status.REJECTED_OTHER_REASON); u.SetMessage(e.Message); } }
internal virtual void SetStatus(RemoteRefUpdate.Status status) { this.status = status; }
/// <summary> /// Create a new instance of this object basing on existing instance for /// configuration. /// </summary> /// <remarks> /// Create a new instance of this object basing on existing instance for /// configuration. State (like /// <see cref="GetMessage()">GetMessage()</see> /// , /// <see cref="GetStatus()">GetStatus()</see> /// ) /// of base object is not shared. Expected old object id is set up from /// scratch, as this constructor may be used for 2-stage push: first one /// being dry run, second one being actual push. /// </remarks> /// <param name="base">configuration base.</param> /// <param name="newExpectedOldObjectId">new expected object id value.</param> /// <exception cref="System.IO.IOException"> /// when I/O error occurred during creating /// <see cref="TrackingRefUpdate">TrackingRefUpdate</see> /// for local tracking branch or srcRef /// of base object no longer can be resolved to any object. /// </exception> public RemoteRefUpdate(NGit.Transport.RemoteRefUpdate @base, ObjectId newExpectedOldObjectId ) : this(@base.localDb, @base.srcRef, @base.remoteName, @base.forceUpdate, (@base .trackingRefUpdate == null ? null : @base.trackingRefUpdate.GetLocalName()), newExpectedOldObjectId ) { }
/// <exception cref="System.IO.IOException"></exception> private void ReadStatusReport(IDictionary <string, RemoteRefUpdate> refUpdates) { string unpackLine = ReadStringLongTimeout(); if (!unpackLine.StartsWith("unpack ")) { throw new PackProtocolException(uri, MessageFormat.Format(JGitText.Get().unexpectedReportLine , unpackLine)); } string unpackStatus = Sharpen.Runtime.Substring(unpackLine, "unpack ".Length); if (!unpackStatus.Equals("ok")) { throw new TransportException(uri, MessageFormat.Format(JGitText.Get().errorOccurredDuringUnpackingOnTheRemoteEnd , unpackStatus)); } string refLine; while ((refLine = pckIn.ReadString()) != PacketLineIn.END) { bool ok = false; int refNameEnd = -1; if (refLine.StartsWith("ok ")) { ok = true; refNameEnd = refLine.Length; } else { if (refLine.StartsWith("ng ")) { ok = false; refNameEnd = refLine.IndexOf(" ", 3); } } if (refNameEnd == -1) { throw new PackProtocolException(MessageFormat.Format(JGitText.Get().unexpectedReportLine2 , uri, refLine)); } string refName = Sharpen.Runtime.Substring(refLine, 3, refNameEnd); string message = (ok ? null : Sharpen.Runtime.Substring(refLine, refNameEnd + 1)); RemoteRefUpdate rru = refUpdates.Get(refName); if (rru == null) { throw new PackProtocolException(MessageFormat.Format(JGitText.Get().unexpectedRefReport , uri, refName)); } if (ok) { rru.SetStatus(RemoteRefUpdate.Status.OK); } else { rru.SetStatus(RemoteRefUpdate.Status.REJECTED_OTHER_REASON); rru.SetMessage(message); } } foreach (RemoteRefUpdate rru_1 in refUpdates.Values) { if (rru_1.GetStatus() == RemoteRefUpdate.Status.AWAITING_REPORT) { throw new PackProtocolException(MessageFormat.Format(JGitText.Get().expectedReportForRefNotReceived , uri, rru_1.GetRemoteName())); } } }
/// <summary> /// Convert push remote refs update specification from /// <see cref="RefSpec">RefSpec</see> /// form /// to /// <see cref="RemoteRefUpdate">RemoteRefUpdate</see> /// . Conversion expands wildcards by matching /// source part to local refs. expectedOldObjectId in RemoteRefUpdate is /// always set as null. Tracking branch is configured if RefSpec destination /// matches source of any fetch ref spec for this transport remote /// configuration. /// </summary> /// <param name="db">local database.</param> /// <param name="specs">collection of RefSpec to convert.</param> /// <param name="fetchSpecs"> /// fetch specifications used for finding localtracking refs. May /// be null or empty collection. /// </param> /// <returns> /// collection of set up /// <see cref="RemoteRefUpdate">RemoteRefUpdate</see> /// . /// </returns> /// <exception cref="System.IO.IOException"> /// when problem occurred during conversion or specification set /// up: most probably, missing objects or refs. /// </exception> public static ICollection<RemoteRefUpdate> FindRemoteRefUpdatesFor(Repository db, ICollection<RefSpec> specs, ICollection<RefSpec> fetchSpecs) { if (fetchSpecs == null) { fetchSpecs = Sharpen.Collections.EmptyList<RefSpec>(); } IList<RemoteRefUpdate> result = new List<RemoteRefUpdate>(); ICollection<RefSpec> procRefs = ExpandPushWildcardsFor(db, specs); foreach (RefSpec spec in procRefs) { string srcSpec = spec.GetSource(); Ref srcRef = db.GetRef(srcSpec); if (srcRef != null) { srcSpec = srcRef.GetName(); } string destSpec = spec.GetDestination(); if (destSpec == null) { // No destination (no-colon in ref-spec), DWIMery assumes src // destSpec = srcSpec; } if (srcRef != null && !destSpec.StartsWith(Constants.R_REFS)) { // Assume the same kind of ref at the destination, e.g. // "refs/heads/foo:master", DWIMery assumes master is also // under "refs/heads/". // string n = srcRef.GetName(); int kindEnd = n.IndexOf('/', Constants.R_REFS.Length); destSpec = Sharpen.Runtime.Substring(n, 0, kindEnd + 1) + destSpec; } bool forceUpdate = spec.IsForceUpdate(); string localName = FindTrackingRefName(destSpec, fetchSpecs); RemoteRefUpdate rru = new RemoteRefUpdate(db, srcSpec, destSpec, forceUpdate, localName , null); result.AddItem(rru); } return result; }
public virtual void TestPushResult() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9" , "refs/heads/master", false, "refs/remotes/test/master", null); Ref @ref = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", ObjectId .FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); refUpdates.AddItem(rru); advertisedRefs.AddItem(@ref); PushResult result = ExecutePush(); NUnit.Framework.Assert.AreEqual(1, result.GetTrackingRefUpdates().Count); NUnit.Framework.Assert.AreEqual(1, result.GetAdvertisedRefs().Count); NUnit.Framework.Assert.AreEqual(1, result.GetRemoteUpdates().Count); NUnit.Framework.Assert.IsNotNull(result.GetTrackingRefUpdate("refs/remotes/test/master" )); NUnit.Framework.Assert.IsNotNull(result.GetAdvertisedRef("refs/heads/master")); NUnit.Framework.Assert.IsNotNull(result.GetRemoteUpdate("refs/heads/master")); }
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 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; } }