public void testWrite1() { // Create a small bundle, an early commit byte[] bundle = makeBundle("refs/heads/aa", db.Resolve("a").Name, null); // Then we clone a new repo from that bundle and do a simple test. This // makes sure // we could Read the bundle we created. Core.Repository newRepo = createBareRepository(); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Core.Ref advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/aa"); Assert.AreEqual(db.Resolve("a").Name, advertisedRef.ObjectId.Name); Assert.AreEqual(db.Resolve("a").Name, newRepo.Resolve("refs/heads/aa").Name); Assert.IsNull(newRepo.Resolve("refs/heads/a")); // Next an incremental bundle bundle = makeBundle( "refs/heads/cc", db.Resolve("c").Name, new GitSharp.Core.RevWalk.RevWalk(db).parseCommit(db.Resolve("a").ToObjectId())); fetchResult = fetchFromBundle(newRepo, bundle); advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/cc"); Assert.AreEqual(db.Resolve("c").Name, advertisedRef.ObjectId.Name); Assert.AreEqual(db.Resolve("c").Name, newRepo.Resolve("refs/heads/cc").Name); Assert.IsNull(newRepo.Resolve("refs/heads/c")); Assert.IsNull(newRepo.Resolve("refs/heads/a")); // still unknown try { // Check that we actually needed the first bundle Core.Repository newRepo2 = createBareRepository(); fetchResult = fetchFromBundle(newRepo2, bundle); Assert.Fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled"); } catch (MissingBundlePrerequisiteException e) { Assert.IsTrue(e.Message.IndexOf(db.Resolve("refs/heads/a").Name) >= 0); } }
ObjectId Resolve(string s) { Core.Repository repo = Git.DefaultRepository; ObjectId r = repo.Resolve(s); if (r == null) { throw die("Not a revision: " + s); } return(r); }
public void testRenameBranchAlsoInPack() { ObjectId rb = db.Resolve("refs/heads/b"); ObjectId rb2 = db.Resolve("refs/heads/b~1"); Assert.AreEqual(Core.Ref.Storage.Packed, db.getRef("refs/heads/b").StorageFormat); RefUpdate updateRef = db.UpdateRef("refs/heads/b"); updateRef.NewObjectId = rb2; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update, "internal check new ref is loose"); Assert.AreEqual(Core.Ref.Storage.LoosePacked, db.getRef("refs/heads/b") .StorageFormat); RefLogWriter.WriteReflog(db, rb, rb, "Just a message", "refs/heads/b"); Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "no log on old branch"); RefRename renameRef = db.RenameRef("refs/heads/b", "refs/heads/new/name"); RefUpdate.RefUpdateResult result = renameRef.Rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.Renamed, result); Assert.AreEqual(rb2, db.Resolve("refs/heads/new/name")); Assert.IsNull(db.Resolve("refs/heads/b")); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader( "new/name").getLastEntry().getComment()); Assert.AreEqual(3, db.ReflogReader("refs/heads/new/name").getReverseEntries().Count); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader("refs/heads/new/name").getReverseEntries()[0].getComment()); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); // make sure b's log file is gone too. Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists); // Create new Repository instance, to reread caches and make sure our // assumptions are persistent. using (Core.Repository ndb = new Core.Repository(db.Directory)) { Assert.AreEqual(rb2, ndb.Resolve("refs/heads/new/name")); Assert.IsNull(ndb.Resolve("refs/heads/b")); } }
public void testWrite0() { // Create a tiny bundle, (well one of) the first commits only byte[] bundle = makeBundle("refs/heads/firstcommit", "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", null); // Then we clone a new repo from that bundle and do a simple test. This // makes sure // we could Read the bundle we created. Core.Repository newRepo = createBareRepository(); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Core.Ref advertisedRef = fetchResult.GetAdvertisedRef("refs/heads/firstcommit"); // We expect firstcommit to appear by id Assert.AreEqual("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", advertisedRef.ObjectId.Name); // ..and by name as the bundle created a new ref Assert.AreEqual("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", newRepo.Resolve(("refs/heads/firstcommit")).Name); }
public void testRenameBranchAlsoInPack() { ObjectId rb = db.Resolve("refs/heads/b"); ObjectId rb2 = db.Resolve("refs/heads/b~1"); Assert.AreEqual(Ref.Storage.Packed, db.getRef("refs/heads/b").StorageFormat); RefUpdate updateRef = db.UpdateRef("refs/heads/b"); updateRef.NewObjectId = rb2; updateRef.IsForceUpdate = true; RefUpdate.RefUpdateResult update = updateRef.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.Forced, update, "internal check new ref is loose"); Assert.AreEqual(Ref.Storage.LoosePacked, db.getRef("refs/heads/b") .StorageFormat); RefLogWriter.WriteReflog(db, rb, rb, "Just a message", "refs/heads/b"); Assert.IsTrue(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists, "no log on old branch"); RefRename renameRef = db.RenameRef("refs/heads/b", "refs/heads/new/name"); RefUpdate.RefUpdateResult result = renameRef.Rename(); Assert.AreEqual(RefUpdate.RefUpdateResult.Renamed, result); Assert.AreEqual(rb2, db.Resolve("refs/heads/new/name")); Assert.IsNull(db.Resolve("refs/heads/b")); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader( "new/name").getLastEntry().getComment()); Assert.AreEqual(3, db.ReflogReader("refs/heads/new/name").getReverseEntries().Count); Assert.AreEqual("Branch: renamed b to new/name", db.ReflogReader("refs/heads/new/name").getReverseEntries()[0].getComment()); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); // make sure b's log file is gone too. Assert.IsFalse(new FileInfo(Path.Combine(db.Directory.FullName, "logs/refs/heads/b")).Exists); // Create new Repository instance, to reread caches and make sure our // assumptions are persistent. Core.Repository ndb = new Core.Repository(db.Directory); Assert.AreEqual(rb2, ndb.Resolve("refs/heads/new/name")); Assert.IsNull(ndb.Resolve("refs/heads/b")); }