public virtual void testReadSymRefToPacked() { writeSymref("HEAD", "refs/heads/b"); global::GitSharp.Core.Ref @ref = db.getRef("HEAD"); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); Assert.IsTrue(@ref.isSymbolic(), "is symref"); @ref = @ref.getTarget(); Assert.AreEqual("refs/heads/b", @ref.Name); Assert.AreEqual(Storage.Packed, @ref.StorageFormat); }
CommitBuilder(TestRepository testRepository, BranchBuilder b) { _testRepository = testRepository; branch = b; global::GitSharp.Core.Ref @ref = _testRepository.db.getRef(branch.@ref); if (@ref != null) { parent(_testRepository.pool.parseCommit(@ref.ObjectId)); } }
public void testNotEmpty_WithPrefix() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); packed = toList(master); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); Assert.IsFalse(map.isEmpty()); // before size was computed Assert.AreEqual(1, map.size()); Assert.IsFalse(map.isEmpty()); // after size was computed Assert.AreSame(master, map.values().iterator().next()); }
public void testGetRef_AnyHeadWithGarbage() { write(PathUtil.CombineFilePath(diskRepo.Directory, "refs/heads/A"), A.Name + "012345 . this is not a standard reference\n" + "#and even more junk\n"); global::GitSharp.Core.Ref r = refdir.getRef("refs/heads/A"); Assert.IsFalse(r.isSymbolic()); Assert.AreEqual(A, r.getObjectId()); Assert.AreEqual("refs/heads/A", r.getName()); Assert.IsFalse(r.isPeeled()); Assert.IsNull(r.getPeeledObjectId()); }
public void testEmpty_WithPrefix() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); packed = toList(master); RefMap map = new RefMap("refs/tags/", packed, loose, resolved); Assert.IsTrue(map.isEmpty()); // before size was computed Assert.AreEqual(0, map.size()); Assert.IsTrue(map.isEmpty()); // after size was computed Assert.IsFalse(map.entrySet().iterator().hasNext()); Assert.IsFalse(map.keySet().iterator().hasNext()); }
public void testClear() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); loose = toList(master); RefMap map = new RefMap("", packed, loose, resolved); Assert.AreSame(master, map.get("refs/heads/master")); map.clear(); Assert.IsNull(map.get("refs/heads/master")); Assert.IsTrue(map.isEmpty()); Assert.AreEqual(0, map.size()); }
public void testGetRef_DiscoversModifiedLoose() { IDictionary <string, global::GitSharp.Core.Ref> all; writeLooseRef("refs/heads/master", A); all = refdir.getRefs(RefDatabase.ALL); Assert.AreEqual(A, all.get(Constants.HEAD).getObjectId()); writeLooseRef("refs/heads/master", B); BUG_WorkAroundRacyGitIssues("refs/heads/master"); global::GitSharp.Core.Ref master = refdir.getRef("refs/heads/master"); Assert.AreEqual(B, master.getObjectId()); }
public void testResolvedNamesSymRef() { global::GitSharp.Core.Ref @ref = db.getRef(Constants.HEAD); Assert.AreEqual(Constants.HEAD, @ref.Name); Assert.IsTrue(@ref.isSymbolic(), "is symbolic ref"); Assert.AreSame(Storage.Loose, @ref.StorageFormat); global::GitSharp.Core.Ref dst = @ref.getTarget(); Assert.IsNotNull(dst, "has target"); Assert.AreEqual("refs/heads/master", dst.Name); Assert.AreSame(dst.ObjectId, @ref.ObjectId); Assert.AreSame(dst.PeeledObjectId, @ref.PeeledObjectId); Assert.AreEqual(dst.IsPeeled, @ref.IsPeeled); }
public void testPut_KeyMustMatchName_WithPrefix() { global::GitSharp.Core.Ref refA = newRef("refs/heads/A", ID_ONE); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); try { map.put("FOO", refA); Assert.Fail("map accepted invalid key/value pair"); } catch (ArgumentException) { // expected } }
public void testPeelLooseTag() { writeLooseRef("refs/tags/v1_0", v1_0); writeLooseRef("refs/tags/current", "ref: refs/tags/v1_0\n"); global::GitSharp.Core.Ref tag = refdir.getRef("refs/tags/v1_0"); global::GitSharp.Core.Ref cur = refdir.getRef("refs/tags/current"); Assert.AreEqual(v1_0, tag.getObjectId()); Assert.IsFalse(tag.isSymbolic()); Assert.IsFalse(tag.isPeeled()); Assert.IsNull(tag.getPeeledObjectId()); Assert.AreEqual(v1_0, cur.getObjectId()); Assert.IsTrue(cur.isSymbolic()); Assert.IsFalse(cur.isPeeled()); Assert.IsNull(cur.getPeeledObjectId()); global::GitSharp.Core.Ref tag_p = refdir.peel(tag); global::GitSharp.Core.Ref cur_p = refdir.peel(cur); Assert.AreNotSame(tag, tag_p); Assert.IsFalse(tag_p.isSymbolic()); Assert.IsTrue(tag_p.isPeeled()); Assert.AreEqual(v1_0, tag_p.getObjectId()); Assert.AreEqual(v1_0.getObject(), tag_p.getPeeledObjectId()); Assert.AreSame(tag_p, refdir.peel(tag_p)); Assert.AreNotSame(cur, cur_p); Assert.AreEqual("refs/tags/current", cur_p.getName()); Assert.IsTrue(cur_p.isSymbolic()); Assert.AreEqual("refs/tags/v1_0", cur_p.getTarget().getName()); Assert.IsTrue(cur_p.isPeeled()); Assert.AreEqual(v1_0, cur_p.getObjectId()); Assert.AreEqual(v1_0.getObject(), cur_p.getPeeledObjectId()); // reuses cached peeling later, but not immediately due to // the implementation so we have to fetch it once. global::GitSharp.Core.Ref tag_p2 = refdir.getRef("refs/tags/v1_0"); Assert.IsFalse(tag_p2.isSymbolic()); Assert.IsTrue(tag_p2.isPeeled()); Assert.AreEqual(v1_0, tag_p2.getObjectId()); Assert.AreEqual(v1_0.getObject(), tag_p2.getPeeledObjectId()); Assert.AreSame(tag_p2, refdir.getRef("refs/tags/v1_0")); Assert.AreSame(tag_p2, refdir.getRef("refs/tags/current").getTarget()); Assert.AreSame(tag_p2, refdir.peel(tag_p2)); }
public void testPut_CollapseResolved() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); global::GitSharp.Core.Ref headU = newRef("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref headR = newRef("HEAD", master); global::GitSharp.Core.Ref a = newRef("refs/heads/A", ID_ONE); loose = toList(headU, master); resolved = toList(headR); RefMap map = new RefMap("", packed, loose, resolved); Assert.IsNull(map.put(a.getName(), a)); Assert.AreSame(a, map.get(a.getName())); Assert.AreSame(headR, map.get("HEAD")); }
public void testReadLoosePackedRef() { global::GitSharp.Core.Ref @ref = db.getRef("refs/heads/master"); Assert.AreEqual(Storage.Packed, @ref.StorageFormat); string path = Path.Combine(db.Directory.FullName, "refs/heads/master"); using (FileStream os = new FileStream(path, System.IO.FileMode.OpenOrCreate)) { byte[] buffer = @ref.ObjectId.Name.getBytes(); os.Write(buffer, 0, buffer.Length); os.WriteByte(Convert.ToByte('\n')); } @ref = db.getRef("refs/heads/master"); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); }
public void testReadSimplePackedRefSameRepo() { global::GitSharp.Core.Ref @ref = db.getRef("refs/heads/master"); ObjectId pid = db.Resolve("refs/heads/master^"); Assert.AreEqual(Storage.Packed, @ref.StorageFormat); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.setNewObjectId(pid); updateRef.setForceUpdate(true); RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); @ref = db.getRef("refs/heads/master"); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); }
public void testGetRef_FetchHead() { // This is an odd special case where we need to make sure we read // exactly the first 40 bytes of the file and nothing further on // that line, or the remainder of the file. write(PathUtil.CombineFilePath(diskRepo.Directory, "FETCH_HEAD"), A.Name + "\tnot-for-merge" + "\tbranch 'master' of git://egit.eclipse.org/jgit\n"); global::GitSharp.Core.Ref r = refdir.getRef("FETCH_HEAD"); Assert.IsFalse(r.isSymbolic()); Assert.AreEqual(A, r.getObjectId()); Assert.AreEqual("FETCH_HEAD", r.getName()); Assert.IsFalse(r.isPeeled()); Assert.IsNull(r.getPeeledObjectId()); }
public void testReadSymRefToLoosePacked() { ObjectId pid = db.Resolve("refs/heads/master^"); RefUpdate updateRef = db.UpdateRef("refs/heads/master"); updateRef.setNewObjectId(pid); updateRef.setForceUpdate(true); RefUpdate.RefUpdateResult update = updateRef.update(); Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, update); // internal writeSymref("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref @ref = db.getRef("HEAD"); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); @ref = @ref.getTarget(); Assert.AreEqual("refs/heads/master", @ref.Name); Assert.AreEqual(Storage.Loose, @ref.StorageFormat); }
public void testToString_NoPrefix() { global::GitSharp.Core.Ref a = newRef("refs/heads/A", ID_ONE); global::GitSharp.Core.Ref b = newRef("refs/heads/B", ID_TWO); packed = toList(a, b); StringBuilder exp = new StringBuilder(); exp.Append("["); exp.Append(a.ToString()); exp.Append(", "); exp.Append(b.ToString()); exp.Append("]"); RefMap map = new RefMap("", packed, loose, resolved); Assert.AreEqual(exp.ToString(), map.ToString()); }
public void testEntryType() { global::GitSharp.Core.Ref a = newRef("refs/heads/A", ID_ONE); global::GitSharp.Core.Ref b = newRef("refs/heads/B", ID_TWO); packed = toList(a, b); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); IteratorBase <RefMap.Ent> itr = map.entrySet().iterator(); RefMap.Ent ent_a = itr.next(); RefMap.Ent ent_b = itr.next(); Assert.AreEqual(ent_a.GetHashCode(), "A".GetHashCode()); Assert.IsTrue(ent_a.Equals(ent_a)); Assert.IsFalse(ent_a.Equals(ent_b)); Assert.AreEqual(a.ToString(), ent_a.ToString()); }
public void testPutReplaceEntry() { global::GitSharp.Core.Ref otherc = newRef(REF_c.Name); Assert.AreNotSame(REF_c, otherc); RefList <global::GitSharp.Core.Ref> one = toList(REF_A, REF_c); RefList <global::GitSharp.Core.Ref> two = one.put(otherc); Assert.AreNotSame(one, two); // one is not modified, but two is Assert.AreEqual(2, one.size()); Assert.AreSame(REF_A, one.get(0)); Assert.AreSame(REF_c, one.get(1)); Assert.AreEqual(2, two.size()); Assert.AreSame(REF_A, two.get(0)); Assert.AreSame(otherc, two.get(1)); }
public void testPut_WithPrefix() { global::GitSharp.Core.Ref refA_one = newRef("refs/heads/A", ID_ONE); global::GitSharp.Core.Ref refA_two = newRef("refs/heads/A", ID_TWO); packed = toList(refA_one); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); Assert.AreSame(refA_one, map.get("A")); Assert.AreSame(refA_one, map.put("A", refA_two)); // map changed, but packed, loose did not Assert.AreSame(refA_two, map.get("A")); Assert.AreSame(refA_one, packed.get(0)); Assert.AreEqual(0, loose.size()); Assert.AreSame(refA_two, map.put("A", refA_one)); Assert.AreSame(refA_one, map.get("A")); }
public void testIterator_FailsAtEnd() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); loose = toList(master); RefMap map = new RefMap("", packed, loose, resolved); IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator(); Assert.IsTrue(itr.hasNext()); Assert.AreSame(master, itr.next()); try { itr.next(); Assert.Fail("iterator allowed next"); } catch (IndexOutOfRangeException) { // expected } }
public void testEntryTypeSet() { global::GitSharp.Core.Ref refA_one = newRef("refs/heads/A", ID_ONE); global::GitSharp.Core.Ref refA_two = newRef("refs/heads/A", ID_TWO); packed = toList(refA_one); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); Assert.AreSame(refA_one, map.get("A")); RefMap.Ent ent = map.entrySet().iterator().next(); Assert.AreEqual("A", ent.getKey()); Assert.AreSame(refA_one, ent.getValue()); Assert.AreSame(refA_one, ent.setValue(refA_two)); Assert.AreSame(refA_two, ent.getValue()); Assert.AreSame(refA_two, map.get("A")); Assert.AreEqual(1, map.size()); }
public void testIterator_RefusesRemove() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); loose = toList(master); RefMap map = new RefMap("", packed, loose, resolved); IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator(); Assert.IsTrue(itr.hasNext()); Assert.AreSame(master, itr.next()); try { itr.remove(); Assert.Fail("iterator allowed remove"); } catch (NotSupportedException) { // expected } }
public void testIterator_MissingUnresolvedSymbolicRefIsBug() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); global::GitSharp.Core.Ref headR = newRef("HEAD", master); loose = toList(master); // loose should have added newRef("HEAD", "refs/heads/master") resolved = toList(headR); var map = new RefMap("", packed, loose, resolved); IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator(); try { itr.hasNext(); Assert.Fail("iterator did not catch bad input"); } catch (InvalidOperationException) { // expected } }
public void testRemove() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); global::GitSharp.Core.Ref headU = newRef("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref headR = newRef("HEAD", master); packed = toList(master); loose = toList(headU, master); resolved = toList(headR); RefMap map = new RefMap("", packed, loose, resolved); Assert.IsNull(map.remove("not.a.reference")); Assert.AreSame(master, map.remove("refs/heads/master")); Assert.IsNull(map.get("refs/heads/master")); Assert.AreSame(headR, map.remove("HEAD")); Assert.IsNull(map.get("HEAD")); Assert.IsTrue(map.isEmpty()); }
public void testPeelCommit() { writeLooseRef("refs/heads/master", A); global::GitSharp.Core.Ref master = refdir.getRef("refs/heads/master"); Assert.AreEqual(A, master.getObjectId()); Assert.IsFalse(master.isPeeled()); Assert.IsNull(master.getPeeledObjectId()); global::GitSharp.Core.Ref master_p = refdir.peel(master); Assert.AreNotSame(master, master_p); Assert.AreEqual(A, master_p.getObjectId()); Assert.IsTrue(master_p.isPeeled()); Assert.IsNull(master_p.getPeeledObjectId()); // reuses cached peeling later, but not immediately due to // the implementation so we have to fetch it once. global::GitSharp.Core.Ref master_p2 = refdir.getRef("refs/heads/master"); Assert.AreNotSame(master, master_p2); Assert.AreEqual(A, master_p2.getObjectId()); Assert.IsTrue(master_p2.isPeeled()); Assert.IsNull(master_p2.getPeeledObjectId()); Assert.AreSame(master_p2, refdir.peel(master_p2)); }
public void testResolvedNamesBranch() { global::GitSharp.Core.Ref @ref = db.getRef("a"); Assert.AreEqual("refs/heads/a", @ref.Name); }
private static global::GitSharp.Core.Ref newRef(String name, global::GitSharp.Core.Ref dst) { return(new SymbolicRef(name, dst)); }