public virtual void TestMissingSubtree_DetectFileAdded_FileModified() { ObjectInserter inserter = db.NewObjectInserter(); ObjectId aFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("a")); ObjectId bFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("b")); ObjectId cFileId1 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-1")); ObjectId cFileId2 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-2")); // Create sub-a/empty, sub-c/empty = hello. ObjectId oldTree; { Tree root = new Tree(db); { Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").SetId(aFileId); subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format())); } { Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").SetId(cFileId1); subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format())); } oldTree = inserter.Insert(Constants.OBJ_TREE, root.Format()); } // Create sub-a/empty, sub-b/empty, sub-c/empty. ObjectId newTree; { Tree root = new Tree(db); { Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").SetId(aFileId); subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format())); } { Tree subB = root.AddTree("sub-b"); subB.AddFile("empty").SetId(bFileId); subB.SetId(inserter.Insert(Constants.OBJ_TREE, subB.Format())); } { Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").SetId(cFileId2); subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format())); } newTree = inserter.Insert(Constants.OBJ_TREE, root.Format()); } inserter.Flush(); inserter.Release(); TreeWalk tw = new TreeWalk(db); tw.Reset(oldTree, newTree); tw.Recursive = true; tw.Filter = TreeFilter.ANY_DIFF; NUnit.Framework.Assert.IsTrue(tw.Next()); NUnit.Framework.Assert.AreEqual("sub-b/empty", tw.PathString); NUnit.Framework.Assert.AreEqual(FileMode.MISSING, tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1)); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, tw.GetObjectId(0)); NUnit.Framework.Assert.AreEqual(bFileId, tw.GetObjectId(1)); NUnit.Framework.Assert.IsTrue(tw.Next()); NUnit.Framework.Assert.AreEqual("sub-c/empty", tw.PathString); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1)); NUnit.Framework.Assert.AreEqual(cFileId1, tw.GetObjectId(0)); NUnit.Framework.Assert.AreEqual(cFileId2, tw.GetObjectId(1)); NUnit.Framework.Assert.IsFalse(tw.Next()); }
/// <exception cref="NGit.Errors.MissingObjectException"></exception> /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception> /// <exception cref="NGit.Errors.CorruptObjectException"></exception> /// <exception cref="System.IO.IOException"></exception> private void AssertEntry(string sha1string, string path, TreeWalk tw) { NUnit.Framework.Assert.IsTrue(tw.Next()); NUnit.Framework.Assert.AreEqual(path, tw.PathString); NUnit.Framework.Assert.AreEqual(sha1string, tw.GetObjectId(1).GetName()); }
public virtual void TestFindObjects() { DirCache tree0 = DirCache.NewInCore(); DirCacheBuilder b0 = tree0.Builder(); ObjectReader or = db.NewObjectReader(); ObjectInserter oi = db.NewObjectInserter(); DirCacheEntry aDotB = MakeEntry("a.b", EXECUTABLE_FILE); b0.Add(aDotB); DirCacheEntry aSlashB = MakeEntry("a/b", REGULAR_FILE); b0.Add(aSlashB); DirCacheEntry aSlashCSlashD = MakeEntry("a/c/d", REGULAR_FILE); b0.Add(aSlashCSlashD); DirCacheEntry aZeroB = MakeEntry("a0b", SYMLINK); b0.Add(aZeroB); b0.Finish(); NUnit.Framework.Assert.AreEqual(4, tree0.GetEntryCount()); ObjectId tree = tree0.WriteTree(oi); // Find the directories that were implicitly created above. TreeWalk tw = new TreeWalk(or); tw.AddTree(tree); ObjectId a = null; ObjectId aSlashC = null; while (tw.Next()) { if (tw.PathString.Equals("a")) { a = tw.GetObjectId(0); tw.EnterSubtree(); while (tw.Next()) { if (tw.PathString.Equals("a/c")) { aSlashC = tw.GetObjectId(0); break; } } break; } } NUnit.Framework.Assert.AreEqual(a, TreeWalk.ForPath(or, "a", tree).GetObjectId(0) ); NUnit.Framework.Assert.AreEqual(a, TreeWalk.ForPath(or, "a/", tree).GetObjectId(0 )); NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a", tree)); NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a/", tree)); NUnit.Framework.Assert.AreEqual(aDotB.GetObjectId(), TreeWalk.ForPath(or, "a.b", tree).GetObjectId(0)); NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a.b", tree)); NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a.b/", tree)); NUnit.Framework.Assert.AreEqual(aDotB.GetObjectId(), TreeWalk.ForPath(or, "a.b/", tree).GetObjectId(0)); NUnit.Framework.Assert.AreEqual(aZeroB.GetObjectId(), TreeWalk.ForPath(or, "a0b", tree).GetObjectId(0)); NUnit.Framework.Assert.AreEqual(aSlashB.GetObjectId(), TreeWalk.ForPath(or, "a/b" , tree).GetObjectId(0)); NUnit.Framework.Assert.AreEqual(aSlashB.GetObjectId(), TreeWalk.ForPath(or, "b", a).GetObjectId(0)); NUnit.Framework.Assert.AreEqual(aSlashC, TreeWalk.ForPath(or, "a/c", tree).GetObjectId (0)); NUnit.Framework.Assert.AreEqual(aSlashC, TreeWalk.ForPath(or, "c", a).GetObjectId (0)); NUnit.Framework.Assert.AreEqual(aSlashCSlashD.GetObjectId(), TreeWalk.ForPath(or, "a/c/d", tree).GetObjectId(0)); NUnit.Framework.Assert.AreEqual(aSlashCSlashD.GetObjectId(), TreeWalk.ForPath(or, "c/d", a).GetObjectId(0)); or.Release(); oi.Release(); }