public void testConstructor() { global::GitSharp.Core.Ref t; SymbolicRef r; t = new Unpeeled(Storage.New, targetName, null); r = new SymbolicRef(name, t); Assert.AreSame(Storage.Loose, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.IsNull(r.getObjectId(), "no id on new ref"); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(t, r.getLeaf(), "leaf is t"); Assert.AreSame(t, r.getTarget(), "target is t"); Assert.IsTrue(r.isSymbolic(), "is symbolic"); t = new Unpeeled(Storage.Packed, targetName, ID_A); r = new SymbolicRef(name, t); Assert.AreSame(Storage.Loose, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.AreSame(ID_A, r.getObjectId()); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(t, r.getLeaf(), "leaf is t"); Assert.AreSame(t, r.getTarget(), "target is t"); Assert.IsTrue(r.isSymbolic(), "is symbolic"); }
public void testConstructor_PeeledStatusNotKnown() { ObjectIdRef r; r = new Unpeeled(Storage.Loose, name, ID_A); Assert.AreSame(Storage.Loose, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.AreSame(ID_A, r.getObjectId()); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(r, r.getLeaf(), "leaf is this"); Assert.AreSame(r, r.getTarget(), "target is this"); Assert.IsFalse(r.isSymbolic(), "not symbolic"); r = new Unpeeled(Storage.Packed, name, ID_A); Assert.AreSame(Storage.Packed, r.getStorage()); r = new Unpeeled(Storage.LoosePacked, name, ID_A); Assert.AreSame(Storage.LoosePacked, r.getStorage()); r = new Unpeeled(Storage.New, name, null); Assert.AreSame(Storage.New, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.IsNull(r.getObjectId(), "no id on new ref"); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(r, r.getLeaf(), "leaf is this"); Assert.AreSame(r, r.getTarget(), "target is this"); Assert.IsFalse(r.isSymbolic(), "not symbolic"); }
public void ShouldReturnValueForAValidRef() { var result = new PushResult(); var r = new Unpeeled(null, "ref", ObjectId.ZeroId); result.AdvertisedRefs.Add("ref", r); Assert.AreEqual(r, result.GetAdvertisedRef("ref")); }
public void ShouldReturnValueForAValidRef() { var connection = new StubConnection(); var r = new Unpeeled(null, "ref", ObjectId.ZeroId); connection.RefsMap.Add("ref", r); Assert.AreEqual(r, connection.GetRef("ref")); }
public void ShouldReturnValueForAValidRef() { var result = new PushResult(); var r = new Unpeeled(null, "ref", ObjectId.ZeroId); var refs = result.AdvertisedRefs; var advRefs = refs.ToDictionary(@ref => @ref.Name); advRefs.Add("ref", r); result.SetAdvertisedRefs(result.URI, advRefs); Assert.AreEqual(r, result.GetAdvertisedRef("ref")); }
public void testPushResult() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, "refs/remotes/test/master", null); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); refUpdates.Add(rru); advertisedRefs.Add(@ref); PushResult result = executePush(); Assert.AreEqual(1, result.TrackingRefUpdates.Count); Assert.AreEqual(1, result.AdvertisedRefs.Count); Assert.AreEqual(1, result.RemoteUpdates.Count); Assert.IsNotNull(result.GetTrackingRefUpdate("refs/remotes/test/master")); Assert.IsNotNull(result.GetAdvertisedRef("refs/heads/master")); Assert.IsNotNull(result.GetRemoteUpdate("refs/heads/master")); }
public override RefUpdate newUpdate(string name, bool detach) { RefList <Ref> packed = getPackedRefs(); Ref @ref = readRef(name, packed); if (@ref != null) { @ref = resolve(@ref, 0, null, null, packed); } if (@ref == null) { @ref = new Unpeeled(Storage.New, name, null); } else if (detach && @ref.isSymbolic()) { @ref = new Unpeeled(Storage.Loose, name, @ref.getObjectId()); } return(new RefDirectoryUpdate(this, @ref)); }
public void testDeleteMaster() { string sn = "refs/heads/master"; RefSpec rs = new RefSpec(":" + sn); Assert.IsFalse(rs.Force); Assert.IsFalse(rs.Wildcard); Assert.AreEqual(sn, rs.Destination); Assert.IsNull(rs.Source); Assert.AreEqual(":" + sn, rs.ToString()); Assert.AreEqual(rs, new RefSpec(rs.ToString())); Core.Ref r = new Unpeeled(Storage.Loose, sn, null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsTrue(rs.MatchDestination(r)); Assert.AreSame(rs, rs.ExpandFromSource(r)); r = new Unpeeled(Storage.Loose, sn + "-and-more", null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsFalse(rs.MatchDestination(r)); }
public void testConstructor_Peeled() { ObjectIdRef r; r = new Unpeeled(Storage.Loose, name, ID_A); Assert.AreSame(Storage.Loose, r.getStorage()); Assert.AreSame(name, r.getName()); Assert.AreSame(ID_A, r.getObjectId()); Assert.IsFalse(r.isPeeled(), "not peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); Assert.AreSame(r, r.getLeaf(), "leaf is this"); Assert.AreSame(r, r.getTarget(), "target is this"); Assert.IsFalse(r.isSymbolic(), "not symbolic"); r = new PeeledNonTag(Storage.Loose, name, ID_A); Assert.IsTrue(r.isPeeled(), "is peeled"); Assert.IsNull(r.getPeeledObjectId(), "no peel id"); r = new PeeledTag(Storage.Loose, name, ID_A, ID_B); Assert.IsTrue(r.isPeeled(), "is peeled"); Assert.AreSame(ID_B, r.getPeeledObjectId()); }
private static RefList <Ref> parsePackedRefs(TextReader br) { var all = new RefList <Ref> .Builder <Ref>(); Ref last = null; bool peeled = false; bool needSort = false; string p; while ((p = br.ReadLine()) != null) { if (p[0] == '#') { if (p.StartsWith(PACKED_REFS_HEADER)) { p = p.Substring(PACKED_REFS_HEADER.Length); peeled = p.Contains(PACKED_REFS_PEELED); } continue; } if (p[0] == '^') { if (last == null) { throw new IOException("Peeled line before ref."); } ObjectId id = ObjectId.FromString(p.Substring(1)); last = new PeeledTag(Storage.Packed, last.getName(), last .getObjectId(), id); all.set(all.size() - 1, last); continue; } int sp = p.IndexOf(' '); ObjectId id2 = ObjectId.FromString(p.Slice(0, sp)); string name = copy(p, sp + 1, p.Length); ObjectIdRef cur; if (peeled) { cur = new PeeledNonTag(Storage.Packed, name, id2); } else { cur = new Unpeeled(Storage.Packed, name, id2); } if (last != null && RefComparator.compareTo(last, cur) > 0) { needSort = true; } all.add(cur); last = cur; } if (needSort) { all.sort(); } return(all.toRefList()); }
public void testForceRemotesOrigin() { string srcn = "refs/heads/*"; string dstn = "refs/remotes/origin/*"; RefSpec rs = new RefSpec("+" + srcn + ":" + dstn); Assert.IsTrue(rs.Force); Assert.IsTrue(rs.Wildcard); Assert.AreEqual(srcn, rs.Source); Assert.AreEqual(dstn, rs.Destination); Assert.AreEqual("+" + srcn + ":" + dstn, rs.ToString()); Assert.AreEqual(rs, new RefSpec(rs.ToString())); Core.Ref r; RefSpec expanded; r = new Unpeeled(Storage.Loose, "refs/heads/master", null); Assert.IsTrue(rs.MatchSource(r)); Assert.IsFalse(rs.MatchDestination(r)); expanded = rs.ExpandFromSource(r); Assert.AreNotSame(rs, expanded); Assert.IsTrue(expanded.Force); Assert.IsFalse(expanded.Wildcard); Assert.AreEqual(r.Name, expanded.Source); Assert.AreEqual("refs/remotes/origin/master", expanded.Destination); r = new Unpeeled(Storage.Loose, "refs/remotes/origin/next", null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsTrue(rs.MatchDestination(r)); r = new Unpeeled(Storage.Loose, "refs/tags/v1.0", null); Assert.IsFalse(rs.MatchSource(r)); Assert.IsFalse(rs.MatchDestination(r)); }
public void testUpdateNonFastForwardForced() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", "refs/heads/master", true, null, null); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.OK, false); }
public void testToString() { ObjectIdRef r; r = new Unpeeled(Storage.Loose, name, ID_A); Assert.AreEqual("Ref[" + name + "=" + ID_A.Name + "]", r.ToString()); }
public void testUpdateUnexpectedRemoteVsForce() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", true, null, ObjectId.FromString("0000000000000000000000000000000000000001")); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_REMOTE_CHANGED, null); }
public void testUpdateUpToDate() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, null, null); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.UP_TO_DATE, null); }
public void testUpdateRejectedByConnection() { connectionUpdateStatus = RemoteRefUpdate.UpdateStatus.REJECTED_OTHER_REASON; RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, null, null); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_OTHER_REASON, null); }
public void testUpdateMixedCases() { RemoteRefUpdate rruOk = new RemoteRefUpdate(db, null, "refs/heads/master", false, null, null); Core.Ref refToChange = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); RemoteRefUpdate rruReject = new RemoteRefUpdate(db, null, "refs/heads/nonexisting", false, null, null); refUpdates.Add(rruOk); refUpdates.Add(rruReject); advertisedRefs.Add(refToChange); executePush(); Assert.AreEqual(RemoteRefUpdate.UpdateStatus.OK, rruOk.Status); Assert.AreEqual(true, rruOk.FastForward); Assert.AreEqual(RemoteRefUpdate.UpdateStatus.NON_EXISTING, rruReject.Status); }
public void testUpdateNonFastForwardUnknownObject() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, null, null); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("0000000000000000000000000000000000000001")); testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_NONFASTFORWARD, null); }
public void testTrackingRefUpdateDisabled() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, null, null); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef")); refUpdates.Add(rru); advertisedRefs.Add(@ref); PushResult result = executePush(); Assert.IsTrue(result.TrackingRefUpdates.Count == 0); }
public void testTrackingRefUpdateOnReject() { RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", "refs/heads/master", false, null, null); Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9")); PushResult result = testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_NONFASTFORWARD, null); Assert.IsTrue(result.TrackingRefUpdates.Count == 0); }