public virtual void TestConstructor_PeeledStatusNotKnown() { ObjectIdRef r; r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, name, ID_A); NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, r.GetStorage()); NUnit.Framework.Assert.AreSame(name, r.GetName()); NUnit.Framework.Assert.AreSame(ID_A, r.GetObjectId()); NUnit.Framework.Assert.IsFalse(r.IsPeeled(), "not peeled"); NUnit.Framework.Assert.IsNull(r.GetPeeledObjectId(), "no peel id"); NUnit.Framework.Assert.AreSame(r, r.GetLeaf(), "leaf is this"); NUnit.Framework.Assert.AreSame(r, r.GetTarget(), "target is this"); NUnit.Framework.Assert.IsFalse(r.IsSymbolic(), "not symbolic"); r = new ObjectIdRef.Unpeeled(RefStorage.PACKED, name, ID_A); NUnit.Framework.Assert.AreEqual(RefStorage.PACKED, r.GetStorage()); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE_PACKED, name, ID_A); NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE_PACKED, r.GetStorage()); r = new ObjectIdRef.Unpeeled(RefStorage.NEW, name, null); NUnit.Framework.Assert.AreEqual(RefStorage.NEW, r.GetStorage()); NUnit.Framework.Assert.AreSame(name, r.GetName()); NUnit.Framework.Assert.IsNull(r.GetObjectId(), "no id on new ref"); NUnit.Framework.Assert.IsFalse(r.IsPeeled(), "not peeled"); NUnit.Framework.Assert.IsNull(r.GetPeeledObjectId(), "no peel id"); NUnit.Framework.Assert.AreSame(r, r.GetLeaf(), "leaf is this"); NUnit.Framework.Assert.AreSame(r, r.GetTarget(), "target is this"); NUnit.Framework.Assert.IsFalse(r.IsSymbolic(), "not symbolic"); }
public virtual void TestConstructor() { Ref t; SymbolicRef r; t = new ObjectIdRef.Unpeeled(RefStorage.NEW, targetName, null); r = new SymbolicRef(name, t); NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, r.GetStorage()); NUnit.Framework.Assert.AreSame(name, r.GetName()); NUnit.Framework.Assert.IsNull(r.GetObjectId(), "no id on new ref"); NUnit.Framework.Assert.IsFalse(r.IsPeeled(), "not peeled"); NUnit.Framework.Assert.IsNull(r.GetPeeledObjectId(), "no peel id"); NUnit.Framework.Assert.AreSame(t, r.GetLeaf(), "leaf is t"); NUnit.Framework.Assert.AreSame(t, r.GetTarget(), "target is t"); NUnit.Framework.Assert.IsTrue(r.IsSymbolic(), "is symbolic"); t = new ObjectIdRef.Unpeeled(RefStorage.PACKED, targetName, ID_A); r = new SymbolicRef(name, t); NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, r.GetStorage()); NUnit.Framework.Assert.AreSame(name, r.GetName()); NUnit.Framework.Assert.AreSame(ID_A, r.GetObjectId()); NUnit.Framework.Assert.IsFalse(r.IsPeeled(), "not peeled"); NUnit.Framework.Assert.IsNull(r.GetPeeledObjectId(), "no peel id"); NUnit.Framework.Assert.AreSame(t, r.GetLeaf(), "leaf is t"); NUnit.Framework.Assert.AreSame(t, r.GetTarget(), "target is t"); NUnit.Framework.Assert.IsTrue(r.IsSymbolic(), "is symbolic"); }
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); }
public virtual void TestToString() { ObjectIdRef r; r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, name, ID_A); NUnit.Framework.Assert.AreEqual("Ref[" + name + "=" + ID_A.Name + "]", r.ToString ()); }
public virtual void TestMasterMaster() { string sn = "refs/heads/master"; RefSpec rs = new RefSpec(sn + ":" + sn); NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate()); NUnit.Framework.Assert.IsFalse(rs.IsWildcard()); NUnit.Framework.Assert.AreEqual(sn, rs.GetSource()); NUnit.Framework.Assert.AreEqual(sn, rs.GetDestination()); NUnit.Framework.Assert.AreEqual(sn + ":" + sn, rs.ToString()); NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString())); Ref r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn, null); NUnit.Framework.Assert.IsTrue(rs.MatchSource(r)); NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r)); NUnit.Framework.Assert.AreSame(rs, rs.ExpandFromSource(r)); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn + "-and-more", null); NUnit.Framework.Assert.IsFalse(rs.MatchSource(r)); NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r)); }
public virtual void TestConstructor_Peeled() { ObjectIdRef r; r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, name, ID_A); NUnit.Framework.Assert.AreEqual(RefStorage.LOOSE, r.GetStorage()); NUnit.Framework.Assert.AreSame(name, r.GetName()); NUnit.Framework.Assert.AreSame(ID_A, r.GetObjectId()); NUnit.Framework.Assert.IsFalse(r.IsPeeled(), "not peeled"); NUnit.Framework.Assert.IsNull(r.GetPeeledObjectId(), "no peel id"); NUnit.Framework.Assert.AreSame(r, r.GetLeaf(), "leaf is this"); NUnit.Framework.Assert.AreSame(r, r.GetTarget(), "target is this"); NUnit.Framework.Assert.IsFalse(r.IsSymbolic(), "not symbolic"); r = new ObjectIdRef.PeeledNonTag(RefStorage.LOOSE, name, ID_A); NUnit.Framework.Assert.IsTrue(r.IsPeeled(), "is peeled"); NUnit.Framework.Assert.IsNull(r.GetPeeledObjectId(), "no peel id"); r = new ObjectIdRef.PeeledTag(RefStorage.LOOSE, name, ID_A, ID_B); NUnit.Framework.Assert.IsTrue(r.IsPeeled(), "is peeled"); NUnit.Framework.Assert.AreSame(ID_B, r.GetPeeledObjectId()); }
/// <exception cref="NGit.Errors.TransportException"></exception> private Ref ReadRef(SortedDictionary<string, Ref> avail, string rn) { string s; string @ref = WalkRemoteObjectDatabase.ROOT_DIR + rn; try { BufferedReader br = this.OpenReader(@ref); try { s = br.ReadLine(); } finally { br.Close(); } } catch (FileNotFoundException) { return null; } catch (IOException err) { throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionReadRef , @ref), err); } if (s == null) { throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionEmptyRef , rn)); } if (s.StartsWith("ref: ")) { string target = Sharpen.Runtime.Substring(s, "ref: ".Length); Ref r = avail.Get(target); if (r == null) { r = this.ReadRef(avail, target); } if (r == null) { r = new ObjectIdRef.Unpeeled(RefStorage.NEW, target, null); } r = new SymbolicRef(rn, r); avail.Put(r.GetName(), r); return r; } if (ObjectId.IsId(s)) { Ref r = new ObjectIdRef.Unpeeled(this.Loose(avail.Get(rn)), rn, ObjectId.FromString (s)); avail.Put(r.GetName(), r); return r; } throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionBadRef , rn, s)); }
public virtual void TestForceRemotesOrigin() { string srcn = "refs/heads/*"; string dstn = "refs/remotes/origin/*"; RefSpec rs = new RefSpec("+" + srcn + ":" + dstn); NUnit.Framework.Assert.IsTrue(rs.IsForceUpdate()); NUnit.Framework.Assert.IsTrue(rs.IsWildcard()); NUnit.Framework.Assert.AreEqual(srcn, rs.GetSource()); NUnit.Framework.Assert.AreEqual(dstn, rs.GetDestination()); NUnit.Framework.Assert.AreEqual("+" + srcn + ":" + dstn, rs.ToString()); NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString())); Ref r; RefSpec expanded; r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", null); NUnit.Framework.Assert.IsTrue(rs.MatchSource(r)); NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r)); expanded = rs.ExpandFromSource(r); NUnit.Framework.Assert.AreNotSame(rs, expanded); NUnit.Framework.Assert.IsTrue(expanded.IsForceUpdate()); NUnit.Framework.Assert.IsFalse(expanded.IsWildcard()); NUnit.Framework.Assert.AreEqual(r.GetName(), expanded.GetSource()); NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", expanded.GetDestination ()); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/remotes/origin/next", null); NUnit.Framework.Assert.IsFalse(rs.MatchSource(r)); NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r)); r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/tags/v1.0", null); NUnit.Framework.Assert.IsFalse(rs.MatchSource(r)); NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r)); }
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 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 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()); }
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 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 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 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 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 ); }
/// <exception cref="System.IO.IOException"></exception> private void ReadPackedRefsImpl(IDictionary<string, Ref> avail, BufferedReader br ) { Ref last = null; bool peeled = false; for (; ; ) { string line = br.ReadLine(); if (line == null) { break; } if (line[0] == '#') { if (line.StartsWith(RefDirectory.PACKED_REFS_HEADER)) { line = Sharpen.Runtime.Substring(line, RefDirectory.PACKED_REFS_HEADER.Length); peeled = line.Contains(RefDirectory.PACKED_REFS_PEELED); } continue; } if (line[0] == '^') { if (last == null) { throw new TransportException(JGitText.Get().peeledLineBeforeRef); } ObjectId id = ObjectId.FromString(Sharpen.Runtime.Substring(line, 1)); last = new ObjectIdRef.PeeledTag(RefStorage.PACKED, last.GetName(), last.GetObjectId (), id); avail.Put(last.GetName(), last); continue; } int sp = line.IndexOf(' '); if (sp < 0) { throw new TransportException(MessageFormat.Format(JGitText.Get().unrecognizedRef, line)); } ObjectId id_1 = ObjectId.FromString(Sharpen.Runtime.Substring(line, 0, sp)); string name = Sharpen.Runtime.Substring(line, sp + 1); if (peeled) { last = new ObjectIdRef.PeeledNonTag(RefStorage.PACKED, name, id_1); } else { last = new ObjectIdRef.Unpeeled(RefStorage.PACKED, name, id_1); } avail.Put(last.GetName(), last); } }
public virtual void TestPullWithUri() { string name = "branch 'test' of http://egit.eclipse.org/jgit.git"; ObjectId objectId = ObjectId.FromString("6db9c2ebf75590eef973081736730a9ea169a0c4" ); Ref remoteBranch = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, name, objectId); Ref master = db.GetRef("refs/heads/master"); string message = formatter.Format(Arrays.AsList(remoteBranch), master); NUnit.Framework.Assert.AreEqual("Merge branch 'test' of http://egit.eclipse.org/jgit.git" , message); }
public virtual void TestCommit() { ObjectId objectId = ObjectId.FromString("6db9c2ebf75590eef973081736730a9ea169a0c4" ); Ref commit = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, objectId.GetName(), objectId ); Ref master = db.GetRef("refs/heads/master"); string message = formatter.Format(Arrays.AsList(commit), master); NUnit.Framework.Assert.AreEqual("Merge commit '6db9c2ebf75590eef973081736730a9ea169a0c4'" , message); }