public void test002_addFile() { var t = new Core.Tree(db) { Id = SomeFakeId }; Assert.IsTrue(t.Id != null); Assert.IsFalse(t.IsModified); const string n = "bob"; FileTreeEntry f = t.AddFile(n); Assert.IsNotNull(f); Assert.AreEqual(n, f.Name); Assert.AreEqual(f.Name, Constants.CHARSET.GetString(f.NameUTF8)); Assert.AreEqual(n, f.FullName); Assert.IsTrue(f.Id == null); Assert.IsTrue(t.IsModified); Assert.IsTrue(t.Id == null); Assert.IsTrue(t.FindBlobMember(f.Name) == f); TreeEntry[] i = t.Members; Assert.IsNotNull(i); Assert.IsTrue(i != null && i.Length > 0); Assert.IsTrue(i != null && i[0] == f); Assert.IsTrue(i != null && i.Length == 1); }
private void addFileToTree(Core.Tree t, string filename, string content) { FileTreeEntry f = t.AddFile(filename); writeTrashFile(f.Name, content); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); }
public void test023_createCommitNonAnullii() { ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]); var almostEmptyTree = new Core.Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree); var commit = new Core.Commit(db) { TreeId = almostEmptyTreeId, Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L, 60), Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L, 60), Encoding = Constants.CHARSET, Message = "\u00dcbergeeks" }; ObjectId cid = new ObjectWriter(db).WriteCommit(commit); Assert.AreEqual("4680908112778718f37e686cbebcc912730b3154", cid.Name); Core.Commit loadedCommit = db.MapCommit(cid); Assert.AreNotSame(loadedCommit, commit); Assert.AreEqual(commit.Message, loadedCommit.Message); }
public void test021_createTreeTag() { ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]); var almostEmptyTree = new Core.Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree); var t = new Core.Tag(db) { Id = almostEmptyTreeId, TagType = "tree", TagName = "test021", Author = new PersonIdent(author, 1154236443000L, -4 * 60), Message = "test021 tagged\n" }; t.Save(); Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.TagId.Name); Core.Tag MapTag = db.MapTag("test021"); Assert.AreEqual("tree", MapTag.TagType); Assert.AreEqual("test021 tagged\n", MapTag.Message); Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), MapTag.Author); Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", MapTag.Id.Name); }
public void testEmpty() { Core.Tree tree = new Core.Tree(db); TreeIterator i = MakeIterator(tree); Assert.IsFalse(i.hasNext()); }
public void test004_addTree() { var t = new Core.Tree(db) { Id = SomeFakeId }; Assert.IsTrue(t.Id != null); Assert.IsFalse(t.IsModified); const string n = "bob"; Core.Tree f = t.AddTree(n); Assert.IsNotNull(f); Assert.AreEqual(n, f.Name); Assert.AreEqual(f.Name, Constants.CHARSET.GetString(f.NameUTF8)); Assert.AreEqual(n, f.FullName); Assert.IsTrue(f.Id == null); Assert.IsTrue(f.Parent == t); Assert.IsTrue(f.Repository == db); Assert.IsTrue(f.IsLoaded); Assert.IsFalse(f.Members.Length > 0); Assert.IsFalse(f.IsRoot); Assert.IsTrue(f.TreeEntry == f); Assert.IsTrue(t.IsModified); Assert.IsTrue(t.Id == null); Assert.IsTrue(t.findTreeMember(f.Name) == f); TreeEntry[] i = t.Members; Assert.IsTrue(i.Length > 0); Assert.IsTrue(i[0] == f); Assert.IsTrue(i.Length == 1); }
public void test007_manyFileLookup() { var t = new Core.Tree(db); var files = new List <FileTreeEntry>(26 * 26); for (char level1 = 'a'; level1 <= 'z'; level1++) { for (char level2 = 'a'; level2 <= 'z'; level2++) { String n = "." + level1 + level2 + "9"; FileTreeEntry f = t.AddFile(n); Assert.IsNotNull(f, "File " + n + " added."); Assert.AreEqual(n, f.Name); files.Add(f); } } Assert.AreEqual(files.Count, t.MemberCount); TreeEntry[] ents = t.Members; Assert.IsNotNull(ents); Assert.AreEqual(files.Count, ents.Length); for (int k = 0; k < ents.Length; k++) { Assert.IsTrue(files[k] == ents[k], "File " + files[k].Name + " is at " + k + "."); } }
private void SetupCase(Dictionary <string, string> headEntries, Dictionary <string, string> mergeEntries, Dictionary <string, string> indexEntries) { _theHead = BuildTree(headEntries); _theMerge = BuildTree(mergeEntries); _theIndex = BuildIndex(indexEntries); }
public void testTricky() { Core.Tree tree = new Core.Tree(db); tree.AddFile("a.b"); tree.AddFile("a.c"); tree.AddFile("a/b.b/b"); tree.AddFile("a/b"); tree.AddFile("a/c"); tree.AddFile("a=c"); tree.AddFile("a=d"); TreeIterator i = MakeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a.b", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a.c", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a/b", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a/b.b/b", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a/c", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a=c", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a=d", i.next().FullName); Assert.IsFalse(i.hasNext()); }
public void test009_SymlinkAndGitlink() { Core.Tree symlinkTree = db.MapTree("symlink"); Assert.IsTrue(symlinkTree.ExistsBlob("symlink.txt"), "Symlink entry exists"); Core.Tree gitlinkTree = db.MapTree("gitlink"); Assert.IsTrue(gitlinkTree.ExistsBlob("submodule"), "Gitlink entry exists"); }
public void testDirectoryFileSimple() { _theIndex = new GitIndex(db); _theIndex.add(trash, writeTrashFile("DF", "DF")); Core.Tree head = db.MapTree(_theIndex.writeTree()); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "DF"))); _theIndex = new GitIndex(db); _theIndex.add(trash, writeTrashFile("DF/DF", "DF/DF")); Core.Tree merge = db.MapTree(_theIndex.writeTree()); _theIndex = new GitIndex(db); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "DF"))); _theIndex.add(trash, writeTrashFile("DF", "DF")); _theReadTree = new WorkDirCheckout(db, trash, head, _theIndex, merge); _theReadTree.PrescanTwoTrees(); Assert.IsTrue(_theReadTree.Removed.Contains("DF")); Assert.IsTrue(_theReadTree.Updated.ContainsKey("DF/DF")); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "DF"))); _theIndex = new GitIndex(db); _theIndex.add(trash, writeTrashFile("DF/DF", "DF/DF")); _theReadTree = new WorkDirCheckout(db, trash, merge, _theIndex, head); _theReadTree.PrescanTwoTrees(); Assert.IsTrue(_theReadTree.Removed.Contains("DF/DF")); Assert.IsTrue(_theReadTree.Updated.ContainsKey("DF")); }
public void testUnchangedSimple() { var index = new GitIndex(db); index.add(trash, writeTrashFile("a.b", "a.b")); index.add(trash, writeTrashFile("a.c", "a.c")); index.add(trash, writeTrashFile("a=c", "a=c")); index.add(trash, writeTrashFile("a=d", "a=d")); var t = new Core.Tree(db); t.AddFile("a.b").Id = ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"); t.AddFile("a.c").Id = ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"); t.AddFile("a=c").Id = ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"); t.AddFile("a=d").Id = ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"); t.Id = new ObjectWriter(db).WriteTree(t); var diff = new IndexDiff(t, index); diff.Diff(); Assert.AreEqual(0, diff.Changed.Count); Assert.AreEqual(0, diff.Added.Count); Assert.AreEqual(0, diff.Removed.Count); Assert.AreEqual(0, diff.Missing.Count); Assert.AreEqual(0, diff.Modified.Count); }
public void testRemoved() { var index = new GitIndex(db); writeTrashFile("file2", "file2"); writeTrashFile("dir/file3", "dir/file3"); var t = new Core.Tree(db); t.AddFile("file2"); t.AddFile("dir/file3"); Assert.AreEqual(2, t.MemberCount); t.FindBlobMember("file2").Id = ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"); var tree2 = (Core.Tree)t.findTreeMember("dir"); tree2.FindBlobMember("file3").Id = ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"); tree2.Id = new ObjectWriter(db).WriteTree(tree2); t.Id = new ObjectWriter(db).WriteTree(t); var diff = new IndexDiff(t, index); diff.Diff(); Assert.AreEqual(2, diff.Removed.Count); Assert.IsTrue(diff.Removed.Contains("file2")); Assert.IsTrue(diff.Removed.Contains("dir/file3")); Assert.AreEqual(0, diff.Changed.Count); Assert.AreEqual(0, diff.Modified.Count); Assert.AreEqual(0, diff.Added.Count); }
public void testModified() { var index = new GitIndex(db); index.add(trash, writeTrashFile("file2", "file2")); index.add(trash, writeTrashFile("dir/file3", "dir/file3")); writeTrashFile("dir/file3", "changed"); var t = new Core.Tree(db); t.AddFile("file2").Id = ObjectId.FromString("0123456789012345678901234567890123456789"); t.AddFile("dir/file3").Id = ObjectId.FromString("0123456789012345678901234567890123456789"); Assert.AreEqual(2, t.MemberCount); var tree2 = (Core.Tree)t.findTreeMember("dir"); tree2.Id = new ObjectWriter(db).WriteTree(tree2); t.Id = new ObjectWriter(db).WriteTree(t); var diff = new IndexDiff(t, index); diff.Diff(); Assert.AreEqual(2, diff.Changed.Count); Assert.IsTrue(diff.Changed.Contains("file2")); Assert.IsTrue(diff.Changed.Contains("dir/file3")); Assert.AreEqual(1, diff.Modified.Count); Assert.IsTrue(diff.Modified.Contains("dir/file3")); Assert.AreEqual(0, diff.Added.Count); Assert.AreEqual(0, diff.Removed.Count); Assert.AreEqual(0, diff.Missing.Count); }
public void testTwoSuccessiveCommitsLinkedToHead() { var repo = createBareRepository(); var workingDirectory = repo.WorkingDirectory; repo.Create(); var objectWriter = new ObjectWriter(repo); FileInfo project1_a_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/A.txt"), "A.txt - first version\n"); FileInfo project1_b_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - first version\n"); var tree = new Core.Tree(repo); Core.Tree projectTree = tree.AddTree("Project-1"); addFile(projectTree, project1_a_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); addFile(projectTree, project1_b_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); tree.Id = (objectWriter.WriteTree(tree)); var commit = new Core.Commit(repo) { Author = new PersonIdent(author, (0L), 60), Committer = new PersonIdent(committer, (0L), 60), Message = "Foo\n\nMessage", TreeEntry = tree }; commit.Save(); var commitId = commit.CommitId; FileInfo project1_b_v2_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - second version\n"); tree = new Core.Tree(repo); projectTree = tree.AddTree("Project-1"); addFile(projectTree, project1_a_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); addFile(projectTree, project1_b_v2_txt, objectWriter); projectTree.Id = (objectWriter.WriteTree(projectTree)); tree.Id = (objectWriter.WriteTree(tree)); commit = new Core.Commit(repo) { Author = new PersonIdent(author, (0L), 60), Committer = new PersonIdent(committer, (0L), 60), Message = "Modified", ParentIds = new[] { commitId }, TreeEntry = tree }; commit.Save(); commitId = commit.CommitId; RefUpdate lck = repo.UpdateRef("refs/heads/master"); Assert.IsNotNull(lck, "obtained lock"); lck.NewObjectId = commitId; Assert.AreEqual(RefUpdate.RefUpdateResult.New, lck.ForceUpdate()); }
public void testSimpleF1() { Core.Tree tree = new Core.Tree(db); tree.AddFile("x"); TreeIterator i = MakeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("x", i.next().Name); }
public void testSimpleT() { Core.Tree tree = new Core.Tree(db); tree.AddTree("a"); TreeIterator i = MakeIterator(tree); Assert.IsFalse(i.hasNext()); }
public void testEmpty() { Core.Tree tree = new Core.Tree(db); TreeIterator i = MakeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("", i.next().FullName); Assert.IsFalse(i.hasNext()); }
public void testEmpty() { var tree = new Core.Tree(db); TreeIterator i = makeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("", i.next().FullName); Assert.IsFalse(i.hasNext()); }
public void test005_addRecursiveTree() { var t = new Core.Tree(db); Core.Tree f = t.AddTree("a/b/c"); Assert.IsNotNull(f); Assert.AreEqual(f.Name, "c"); Assert.AreEqual(f.Parent.Name, "b"); Assert.AreEqual(f.Parent.Parent.Name, "a"); Assert.IsTrue(t == f.Parent.Parent.Parent, "t is great-grandparent"); }
public void test002_WriteEmptyTree2() { // File shouldn't exist as it is in a test pack. // var t = new Core.Tree(db); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); Assert.AreEqual("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.Id.Name); var o = new FileInfo(db.Directory + "/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904"); Assert.IsFalse(o.IsFile(), "Exists " + o); }
public void testIndexOnlySubDirs() { var index = new GitIndex(db); var mainTree = new Core.Tree(db); index.add(trash, writeTrashFile("foo/bar/baz", "foobar")); index.add(trash, writeTrashFile("asdf", "asdf")); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.AreEqual("asdf", IndexOnlyEntriesVisited[0]); Assert.AreEqual("foo/bar/baz", IndexOnlyEntriesVisited[1]); }
public void testSimpleT() { Core.Tree tree = new Core.Tree(db); tree.AddTree("a"); TreeIterator i = MakeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a", i.next().FullName); Assert.IsFalse(i.hasNext()); }
public void test009_CreateCommitOldFormat() { writeTrashFile(".git/config", "[core]\n" + "legacyHeaders=1\n"); db.Config.load(); Assert.AreEqual(true, db.Config.getBoolean("core", "legacyHeaders", false)); var t = new Core.Tree(db); FileTreeEntry f = t.AddFile("i-am-a-file"); writeTrashFile(f.Name, "and this is the data in me\n"); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), t.TreeId); var c = new Core.Commit(db) { Author = (new PersonIdent(author, 1154236443000L, -4 * 60)), Committer = (new PersonIdent(committer, 1154236443000L, -4 * 60)), Message = ("A Commit\n"), TreeEntry = t }; Assert.AreEqual(t.TreeId, c.TreeId); c.Save(); ObjectId cmtid = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099"); Assert.AreEqual(cmtid, c.CommitId); // Verify the commit we just wrote is in the correct format. var xis = new XInputStream(new FileStream(db.ToFile(cmtid).FullName, System.IO.FileMode.Open, FileAccess.Read)); try { Assert.AreEqual(0x78, xis.ReadUInt8()); Assert.AreEqual(0x9c, xis.ReadUInt8()); Assert.IsTrue(0x789c % 31 == 0); } finally { xis.Close(); } // Verify we can Read it. Core.Commit c2 = db.MapCommit(cmtid); Assert.IsNotNull(c2); Assert.AreEqual(c.Message, c2.Message); Assert.AreEqual(c.TreeId, c2.TreeId); Assert.AreEqual(c.Author, c2.Author); Assert.AreEqual(c.Committer, c2.Committer); }
public void testSimpleF2() { var tree = new Core.Tree(db); tree.AddFile("a"); tree.AddFile("x"); TreeIterator i = makeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a", i.next().Name); Assert.AreEqual("x", i.next().Name); Assert.IsTrue(i.hasNext()); Assert.AreEqual("", i.next().FullName); Assert.IsFalse(i.hasNext()); }
private Core.Tree BuildTree(Dictionary <string, string> headEntries) { var tree = new Core.Tree(db); if (headEntries != null) { foreach (var pair in headEntries) { tree.AddFile(pair.Key).Id = GenSha1(pair.Value); } } return(tree); }
public void testTreeOnlyOneLevel() { var index = new GitIndex(db); var mainTree = new Core.Tree(db); mainTree.AddFile("foo"); mainTree.AddFile("bar"); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.IsTrue(TreeOnlyEntriesVisited[0].Equals("bar")); Assert.IsTrue(TreeOnlyEntriesVisited[1].Equals("foo")); }
public void testIndexOnlyOneLevel() { var index = new GitIndex(db); var mainTree = new Core.Tree(db); index.add(trash, writeTrashFile("foo", "foo")); index.add(trash, writeTrashFile("bar", "bar")); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.AreEqual(2, IndexOnlyEntriesVisited.Count); Assert.IsTrue(IndexOnlyEntriesVisited[0].Equals("bar")); Assert.IsTrue(IndexOnlyEntriesVisited[1].Equals("foo")); }
public void Write_Simple_Commit() { var t = new Core.Tree(db); FileTreeEntry f = t.AddFile("i-am-a-file"); writeTrashFile(f.Name, "and this is the data in me\r\n\r\n"); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); //new ObjectChecker().checkBlob(Constants.CHARSET.GetString(db.OpenObject(t.TreeId).getBytes()).ToCharArray()); string s = new Inspector(db).Inspect(t.Id); string s1 = Inspector.Inspect("Resources/single_file_commit", "16c0beaf7523eb3ef5df45bd42dd4fc6343de864"); string s2 = Inspector.Inspect("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448"); string s3 = Inspector.Inspect("Resources/single_file_commit", "95ea6a6859af6791464bd8b6de76ad5a6f9fad81"); //tree 917c130bd4fa5bf2df0c399dc1b03401860aa448\nauthor henon <*****@*****.**> 1245946742 +0200\ncommitter henon <*****@*****.**> 1245946742 +0200\n\nA Commit\n" Assert.AreEqual(ObjectId.FromString("917c130bd4fa5bf2df0c399dc1b03401860aa448"), t.Id); var c = new Core.Commit(db) { Author = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 2 * 60)), Committer = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 2 * 60)), Message = ("A Commit\n"), TreeEntry = (t) }; Assert.AreEqual(t.TreeId, c.TreeId); c.Save(); string s_c = new Inspector(db).Inspect(c.CommitId); ObjectId cmtid = ObjectId.FromString("16c0beaf7523eb3ef5df45bd42dd4fc6343de864"); Assert.AreEqual(cmtid, c.CommitId); // Verify the commit we just wrote is in the correct format. //using (var xis = new XInputStream(new FileStream(db.ToFile(cmtid).FullName, System.IO.FileMode.Open, FileAccess.Read))) //{ // Assert.AreEqual(0x78, xis.ReadUInt8()); // Assert.AreEqual(0x9c, xis.ReadUInt8()); // Assert.IsTrue(0x789c % 31 == 0); //} // Verify we can Read it. Core.Commit c2 = db.MapCommit(cmtid.ToString()); Assert.IsNotNull(c2); Assert.AreEqual(c.Message, c2.Message); Assert.AreEqual(c.TreeId, c2.TreeId); Assert.AreEqual(c.Author, c2.Author); Assert.AreEqual(c.Committer, c2.Committer); }
public void test006_addDeepTree() { var t = new Core.Tree(db); Core.Tree e = t.AddTree("e"); Assert.IsNotNull(e); Assert.IsTrue(e.Parent == t); Core.Tree f = t.AddTree("f"); Assert.IsNotNull(f); Assert.IsTrue(f.Parent == t); Core.Tree g = f.AddTree("g"); Assert.IsNotNull(g); Assert.IsTrue(g.Parent == f); Core.Tree h = g.AddTree("h"); Assert.IsNotNull(h); Assert.IsTrue(h.Parent == g); h.Id = SomeFakeId; Assert.IsTrue(!h.IsModified); g.Id = SomeFakeId; Assert.IsTrue(!g.IsModified); f.Id = SomeFakeId; Assert.IsTrue(!f.IsModified); e.Id = SomeFakeId; Assert.IsTrue(!e.IsModified); t.Id = SomeFakeId; Assert.IsTrue(!t.IsModified); Assert.AreEqual("f/g/h", h.FullName); Assert.IsTrue(t.findTreeMember(h.FullName) == h); Assert.IsTrue(t.FindBlobMember("f/z") == null); Assert.IsTrue(t.FindBlobMember("y/z") == null); FileTreeEntry i = h.AddFile("i"); Assert.IsNotNull(i); Assert.AreEqual("f/g/h/i", i.FullName); Assert.IsTrue(t.FindBlobMember(i.FullName) == i); Assert.IsTrue(h.IsModified); Assert.IsTrue(g.IsModified); Assert.IsTrue(f.IsModified); Assert.IsTrue(!e.IsModified); Assert.IsTrue(t.IsModified); Assert.IsTrue(h.Id == null); Assert.IsTrue(g.Id == null); Assert.IsTrue(f.Id == null); Assert.IsTrue(e.Id != null); Assert.IsTrue(t.Id == null); }
public void testBoth() { var index = new GitIndex(db); var mainTree = new Core.Tree(db); index.add(trash, writeTrashFile("a", "a")); mainTree.AddFile("b/b"); index.add(trash, writeTrashFile("c", "c")); mainTree.AddFile("c"); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.IsTrue(IndexOnlyEntriesVisited.Contains("a")); Assert.IsTrue(TreeOnlyEntriesVisited.Contains("b/b")); Assert.IsTrue(BothVisited.Contains("c")); }
public void testEnsureCommitTimeAndTimeZoneOffsetArePreserved() { long commitTime = 1154236443000L; int tz = -4 * 60; Core.Tree t = new Core.Tree(db); addFileToTree(t, "i-am-a-file", "and this is the data in me\n"); commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer, commitTime, tz)); IList<ReflogReader.Entry> entries = db.ReflogReader(Constants.HEAD).getReverseEntries(); Assert.AreEqual(1, entries.Count); var entry = entries[0]; Assert.AreEqual(commitTime, entry.getWho().When); Assert.AreEqual(tz, entry.getWho().TimeZoneOffset); }
public void testAdded2() { var index = new GitIndex(db); writeTrashFile("test/für henon.txt", "Weißebier"); var tree = new Core.Tree(db); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "test/für henon.txt"))); var diff = new IndexDiff(tree, index); diff.Diff(); Assert.AreEqual(1, diff.Added.Count); Assert.IsTrue(diff.Added.Contains("test/für henon.txt")); Assert.AreEqual(0, diff.Changed.Count); Assert.AreEqual(0, diff.Modified.Count); Assert.AreEqual(0, diff.Removed.Count); }
public void testAdded() { var index = new GitIndex(db); writeTrashFile("file1", "file1"); writeTrashFile("dir/subfile", "dir/subfile"); var tree = new Core.Tree(db); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "file1"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "dir/subfile"))); var diff = new IndexDiff(tree, index); diff.Diff(); Assert.AreEqual(2, diff.Added.Count); Assert.IsTrue(diff.Added.Contains("file1")); Assert.IsTrue(diff.Added.Contains("dir/subfile")); Assert.AreEqual(0, diff.Changed.Count); Assert.AreEqual(0, diff.Modified.Count); Assert.AreEqual(0, diff.Removed.Count); }
public void testEnsureLogTimeAndTimeZoneOffsetAreCurrentValues() { long commitTime = 1154236443000L; int tz = -4 * 60; Core.Tree t = new Core.Tree(db); addFileToTree(t, "i-am-a-file", "and this is the data in me\n"); commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer, commitTime, tz)); IList<ReflogReader.Entry> entries = db.ReflogReader(Constants.HEAD).getReverseEntries(); Assert.AreEqual(1, entries.Count); var entry = entries[0]; SystemReader mockSystemReader = SystemReader.getInstance(); long fakeCurrentTime = mockSystemReader.getCurrentTime(); long remainder = fakeCurrentTime % 1000; fakeCurrentTime -= remainder; // Second based Unix time format is used to store timetamps in the log. Thus, milliseconds are truncated. Assert.AreEqual(fakeCurrentTime, entry.getWho().When); Assert.AreEqual(mockSystemReader.getTimezone(fakeCurrentTime), entry.getWho().TimeZoneOffset); }
public void testlogAllRefUpdates() { long commitTime = 1154236443000L; int tz = -4 * 60; // check that there are no entries in the reflog and turn off writing // reflogs Assert.AreEqual(0, db.ReflogReader(Constants.HEAD).getReverseEntries().Count, "there should be no entries in reflog"); db.Config.setBoolean("core", null, "logallrefupdates", false); // do one commit and check that reflog size is 0: no reflogs should be // written Core.Tree t = new Core.Tree(db); addFileToTree(t, "i-am-a-file", "and this is the data in me\n"); commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer, commitTime, tz)); commitTime += 100; Assert.IsTrue( db.ReflogReader(Constants.HEAD).getReverseEntries().Count == 0, "Reflog for HEAD still contain no entry"); // set the logAllRefUpdates parameter to true and check it db.Config.setBoolean("core", null, "logallrefupdates", true); Assert.IsTrue(db.Config.getCore().isLogAllRefUpdates()); // do one commit and check that reflog size is increased to 1 addFileToTree(t, "i-am-another-file", "and this is other data in me\n"); commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer, commitTime, tz)); commitTime += 100; Assert.IsTrue(db.ReflogReader(Constants.HEAD).getReverseEntries().Count == 1, "Reflog for HEAD should contain one entry"); // set the logAllRefUpdates parameter to false and check it db.Config.setBoolean("core", null, "logallrefupdates", false); Assert.IsFalse(db.Config.getCore().isLogAllRefUpdates()); // do one commit and check that reflog size is 2 addFileToTree(t, "i-am-anotheranother-file", "and this is other other data in me\n"); commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), new PersonIdent(committer, commitTime, tz)); Assert.IsTrue(db.ReflogReader(Constants.HEAD).getReverseEntries().Count == 2, "Reflog for HEAD should contain two entries"); }
private void SetupCase(Dictionary<string, string> headEntries, Dictionary<string, string> mergeEntries, Dictionary<string, string> indexEntries) { _theHead = BuildTree(headEntries); _theMerge = BuildTree(mergeEntries); _theIndex = BuildIndex(indexEntries); }
public void Write_Tree() { var t = new Core.Tree(db); FileTreeEntry f = t.AddFile("i-am-a-file"); writeTrashFile(f.Name, "and this is the data in me\r\n\r\n"); Assert.AreEqual(File.ReadAllText("Resources/single_file_commit/i-am-a-file"), File.ReadAllText(db.WorkingDirectory.FullName + "/i-am-a-file")); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); var id = t.Id; var b1 = new BinaryReader(new Inspector(db).ContentStream(id)); b1.BaseStream.Position = b1.BaseStream.Length - 21; var b2 = new BinaryReader(Inspector.ContentStream("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448")); b2.BaseStream.Position = b2.BaseStream.Length - 21; Assert.AreEqual(b2.ReadByte(), b1.ReadByte()); var git_w1=b2.ReadInt32(); var git_w2=b2.ReadInt32(); var git_w3 = b2.ReadInt32(); var git_w4 = b2.ReadInt32(); var git_w5 = b2.ReadInt32(); b2.BaseStream.Position = b2.BaseStream.Length-20; var git_id = ObjectId.FromRaw(b2.ReadBytes(20)); var w1 = b1.ReadInt32(); var w2= b1.ReadInt32(); b1.Close(); b2.Close(); Assert.AreEqual(git_w1,w1); Assert.AreEqual(git_w2, w2); Assert.AreEqual("917c130bd4fa5bf2df0c399dc1b03401860aa448", id.ToString()); var s_git = Inspector.Inspect("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448"); var s = new Inspector(db).Inspect(id); Assert.AreEqual(s_git, s); }
public void test002_WriteEmptyTree() { // One of our test packs contains the empty tree object. If the pack is // open when we Create it we won't write the object file out as a loose // object (as it already exists in the pack). // Core.Repository newdb = createBareRepository(); var t = new Core.Tree(newdb); t.Accept(new WriteTree(trash, newdb), TreeEntry.MODIFIED_ONLY); Assert.AreEqual("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.Id.Name); var o = new FileInfo(newdb.Directory + "/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904"); Assert.IsTrue(o.IsFile(), "Exists " + o); Assert.IsTrue(o.IsReadOnly, "Read-only " + o); }
public void Write_Simple_Commit() { var t = new Core.Tree(db); FileTreeEntry f = t.AddFile("i-am-a-file"); writeTrashFile(f.Name, "and this is the data in me\r\n\r\n"); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); //new ObjectChecker().checkBlob(Constants.CHARSET.GetString(db.OpenObject(t.TreeId).getBytes()).ToCharArray()); string s = new Inspector(db).Inspect(t.Id); string s1 = Inspector.Inspect("Resources/single_file_commit", "16c0beaf7523eb3ef5df45bd42dd4fc6343de864"); string s2 = Inspector.Inspect("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448"); string s3 = Inspector.Inspect("Resources/single_file_commit", "95ea6a6859af6791464bd8b6de76ad5a6f9fad81"); //tree 917c130bd4fa5bf2df0c399dc1b03401860aa448\nauthor henon <*****@*****.**> 1245946742 +0200\ncommitter henon <*****@*****.**> 1245946742 +0200\n\nA Commit\n" Assert.AreEqual(ObjectId.FromString("917c130bd4fa5bf2df0c399dc1b03401860aa448"), t.Id); var c = new Core.Commit(db) { Author = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 2*60)), Committer = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 2*60)), Message = ("A Commit\n"), TreeEntry = (t) }; Assert.AreEqual(t.TreeId, c.TreeId); c.Save(); string s_c = new Inspector(db).Inspect(c.CommitId); ObjectId cmtid = ObjectId.FromString("16c0beaf7523eb3ef5df45bd42dd4fc6343de864"); Assert.AreEqual(cmtid, c.CommitId); // Verify the commit we just wrote is in the correct format. //using (var xis = new XInputStream(new FileStream(db.ToFile(cmtid).FullName, System.IO.FileMode.Open, FileAccess.Read))) //{ // Assert.AreEqual(0x78, xis.ReadUInt8()); // Assert.AreEqual(0x9c, xis.ReadUInt8()); // Assert.IsTrue(0x789c % 31 == 0); //} // Verify we can Read it. Core.Commit c2 = db.MapCommit(cmtid.ToString()); Assert.IsNotNull(c2); Assert.AreEqual(c.Message, c2.Message); Assert.AreEqual(c.TreeId, c2.TreeId); Assert.AreEqual(c.Author, c2.Author); Assert.AreEqual(c.Committer, c2.Committer); }
public void test022_createCommitTag() { ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]); var almostEmptyTree = new Core.Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree); var almostEmptyCommit = new Core.Commit(db) { Author = new PersonIdent(author, 1154236443000L, -2*60), Committer = new PersonIdent(author, 1154236443000L, -2*60), Message = "test022\n", TreeId = almostEmptyTreeId }; ObjectId almostEmptyCommitId = new ObjectWriter(db).WriteCommit(almostEmptyCommit); var t = new Core.Tag(db) { Id = almostEmptyCommitId, TagType = "commit", TagName = "test022", Author = new PersonIdent(author, 1154236443000L, -4*60), Message = "test022 tagged\n" }; t.Save(); Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.TagId.Name); Core.Tag mapTag = db.MapTag("test022"); Assert.AreEqual("commit", mapTag.TagType); Assert.AreEqual("test022 tagged\n", mapTag.Message); Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.Author); Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.Id.Name); }
public void test012_SubtreeExternalSorting() { ObjectId emptyBlob = new ObjectWriter(db).WriteBlob(new byte[0]); var t = new Core.Tree(db); FileTreeEntry e0 = t.AddFile("a-"); FileTreeEntry e1 = t.AddFile("a-b"); FileTreeEntry e2 = t.AddFile("a/b"); FileTreeEntry e3 = t.AddFile("a="); FileTreeEntry e4 = t.AddFile("a=b"); e0.Id = emptyBlob; e1.Id = emptyBlob; e2.Id = emptyBlob; e3.Id = emptyBlob; e4.Id = emptyBlob; t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); Assert.AreEqual(ObjectId.FromString("b47a8f0a4190f7572e11212769090523e23eb1ea"), t.Id); }
public void test021_createTreeTag() { ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]); var almostEmptyTree = new Core.Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree); var t = new Core.Tag(db) { Id = almostEmptyTreeId, TagType = "tree", TagName = "test021", Author = new PersonIdent(author, 1154236443000L, -4*60), Message = "test021 tagged\n" }; t.Save(); Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.TagId.Name); Core.Tag MapTag = db.MapTag("test021"); Assert.AreEqual("tree", MapTag.TagType); Assert.AreEqual("test021 tagged\n", MapTag.Message); Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60), MapTag.Author); Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", MapTag.Id.Name); }
public void test009_CreateCommitOldFormat() { writeTrashFile(".git/config", "[core]\n" + "legacyHeaders=1\n"); db.Config.load(); Assert.AreEqual(true, db.Config.getBoolean("core", "legacyHeaders", false)); var t = new Core.Tree(db); FileTreeEntry f = t.AddFile("i-am-a-file"); writeTrashFile(f.Name, "and this is the data in me\n"); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), t.TreeId); var c = new Core.Commit(db) { Author = (new PersonIdent(author, 1154236443000L, -4*60)), Committer = (new PersonIdent(committer, 1154236443000L, -4*60)), Message = ("A Commit\n"), TreeEntry = t }; Assert.AreEqual(t.TreeId, c.TreeId); c.Save(); ObjectId cmtid = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099"); Assert.AreEqual(cmtid, c.CommitId); // Verify the commit we just wrote is in the correct format. var xis = new XInputStream(new FileStream(db.ToFile(cmtid).FullName, System.IO.FileMode.Open, FileAccess.Read)); try { Assert.AreEqual(0x78, xis.ReadUInt8()); Assert.AreEqual(0x9c, xis.ReadUInt8()); Assert.IsTrue(0x789c % 31 == 0); } finally { xis.Close(); } // Verify we can Read it. Core.Commit c2 = db.MapCommit(cmtid); Assert.IsNotNull(c2); Assert.AreEqual(c.Message, c2.Message); Assert.AreEqual(c.TreeId, c2.TreeId); Assert.AreEqual(c.Author, c2.Author); Assert.AreEqual(c.Committer, c2.Committer); }
public void test003_WriteShouldBeEmptyTree() { Core.Tree t = new Core.Tree(db); ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]); t.AddFile("should-be-empty").Id = emptyId; t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); Assert.AreEqual("7bb943559a305bdd6bdee2cef6e5df2413c3d30a", t.Id.Name); var o = new FileInfo(db.Directory + "/objects/7b/b943559a305bdd6bdee2cef6e5df2413c3d30a"); Assert.IsTrue(o.IsFile(), "Exists " + o); Assert.IsTrue(o.IsReadOnly, "Read-only " + o); o = new FileInfo(db.Directory + "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391"); Assert.IsTrue(o.IsFile(), "Exists " + o); Assert.IsTrue(o.IsReadOnly, "Read-only " + o); }
private Core.Tree BuildTree(Dictionary<string, string> headEntries) { var tree = new Core.Tree(db); if (headEntries != null) { foreach (var pair in headEntries) { tree.AddFile(pair.Key).Id = GenSha1(pair.Value); } } return tree; }
public void test024_createCommitNonAscii() { ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]); var almostEmptyTree = new Core.Tree(db); almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree); var commit = new Core.Commit(db) { TreeId = almostEmptyTreeId, Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L, 60), Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L, 60), Encoding = Encoding.GetEncoding("ISO-8859-1"), Message = "\u00dcbergeeks" }; ObjectId cid = new ObjectWriter(db).WriteCommit(commit); var s = new Inspector(db).Inspect(cid); Assert.AreEqual("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.ToString()); }
public void testRules1thru3_NoIndexEntry() { var index = new GitIndex(db); var head = new Core.Tree(db); FileTreeEntry entry = head.AddFile("foo"); ObjectId expected = ObjectId.FromString("ba78e065e2c261d4f7b8f42107588051e87e18e9"); entry.Id = expected; var merge = new Core.Tree(db); var checkout = new WorkDirCheckout(db, trash, head, index, merge); checkout.PrescanTwoTrees(); Assert.IsTrue(checkout.Removed.Contains("foo")); checkout = new WorkDirCheckout(db, trash, merge, index, head); checkout.PrescanTwoTrees(); Assert.AreEqual(expected, checkout.Updated["foo"]); ObjectId id2 = ObjectId.FromString("ba78e065e2c261d4f7b8f42107588051e87e18ee"); merge.AddFile("foo").Id = id2; checkout = new WorkDirCheckout(db, trash, head, index, merge); checkout.PrescanTwoTrees(); Assert.AreEqual(id2, checkout.Updated["foo"]); }
public void test026_CreateCommitMultipleparents() { db.Config.load(); var t = new Core.Tree(db); FileTreeEntry f = t.AddFile("i-am-a-file"); writeTrashFile(f.Name, "and this is the data in me\n"); t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), t.TreeId); var c1 = new Core.Commit(db) { Author = new PersonIdent(author, 1154236443000L, -4*60), Committer = new PersonIdent(committer, 1154236443000L, -4*60), Message = "A Commit\n", TreeEntry = t }; Assert.AreEqual(t.TreeId, c1.TreeId); c1.Save(); ObjectId cmtid1 = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099"); Assert.AreEqual(cmtid1, c1.CommitId); var c2 = new Core.Commit(db) { Author = new PersonIdent(author, 1154236443000L, -4*60), Committer = new PersonIdent(committer, 1154236443000L, -4*60), Message = "A Commit 2\n", TreeEntry = t }; Assert.AreEqual(t.TreeId, c2.TreeId); c2.ParentIds = new[] { c1.CommitId }; c2.Save(); ObjectId cmtid2 = ObjectId.FromString("95d068687c91c5c044fb8c77c5154d5247901553"); Assert.AreEqual(cmtid2, c2.CommitId); Core.Commit rm2 = db.MapCommit(cmtid2); Assert.AreNotSame(c2, rm2); // assert the parsed objects is not from the cache Assert.AreEqual(c2.Author, rm2.Author); Assert.AreEqual(c2.CommitId, rm2.CommitId); Assert.AreEqual(c2.Message, rm2.Message); Assert.AreEqual(c2.TreeEntry.TreeId, rm2.TreeEntry.TreeId); Assert.AreEqual(1, rm2.ParentIds.Length); Assert.AreEqual(c1.CommitId, rm2.ParentIds[0]); var c3 = new Core.Commit(db) { Author = new PersonIdent(author, 1154236443000L, -4*60), Committer = new PersonIdent(committer, 1154236443000L, -4*60), Message = "A Commit 3\n", TreeEntry = t }; Assert.AreEqual(t.TreeId, c3.TreeId); c3.ParentIds = new[] { c1.CommitId, c2.CommitId }; c3.Save(); ObjectId cmtid3 = ObjectId.FromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4"); Assert.AreEqual(cmtid3, c3.CommitId); Core.Commit rm3 = db.MapCommit(cmtid3); Assert.AreNotSame(c3, rm3); // assert the parsed objects is not from the cache Assert.AreEqual(c3.Author, rm3.Author); Assert.AreEqual(c3.CommitId, rm3.CommitId); Assert.AreEqual(c3.Message, rm3.Message); Assert.AreEqual(c3.TreeEntry.TreeId, rm3.TreeEntry.TreeId); Assert.AreEqual(2, rm3.ParentIds.Length); Assert.AreEqual(c1.CommitId, rm3.ParentIds[0]); Assert.AreEqual(c2.CommitId, rm3.ParentIds[1]); var c4 = new Core.Commit(db) { Author = new PersonIdent(author, 1154236443000L, -4*60), Committer = new PersonIdent(committer, 1154236443000L, -4*60), Message = "A Commit 4\n", TreeEntry = t }; Assert.AreEqual(t.TreeId, c3.TreeId); c4.ParentIds = new[] { c1.CommitId, c2.CommitId, c3.CommitId }; c4.Save(); ObjectId cmtid4 = ObjectId.FromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27"); Assert.AreEqual(cmtid4, c4.CommitId); Core.Commit rm4 = db.MapCommit(cmtid4); Assert.AreNotSame(c4, rm3); // assert the parsed objects is not from the cache Assert.AreEqual(c4.Author, rm4.Author); Assert.AreEqual(c4.CommitId, rm4.CommitId); Assert.AreEqual(c4.Message, rm4.Message); Assert.AreEqual(c4.TreeEntry.TreeId, rm4.TreeEntry.TreeId); Assert.AreEqual(3, rm4.ParentIds.Length); Assert.AreEqual(c1.CommitId, rm4.ParentIds[0]); Assert.AreEqual(c2.CommitId, rm4.ParentIds[1]); Assert.AreEqual(c3.CommitId, rm4.ParentIds[2]); }
public void testMissingSubtree_DetectFileAdded_FileModified() { var ow = new ObjectWriter(db); ObjectId aFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("a")); ObjectId bFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("b")); ObjectId cFileId1 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-1")); ObjectId cFileId2 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-2")); // Create sub-a/empty, sub-c/empty = hello. Func<ObjectId> oldTree = () => { var root = new Core.Tree(db); Core.Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").Id = aFileId; subA.Id = ow.WriteTree(subA); Core.Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").Id = cFileId1; subC.Id = ow.WriteTree(subC); return ow.WriteTree(root); }; // Create sub-a/empty, sub-b/empty, sub-c/empty. Func<ObjectId> newTree = () => { var root = new Core.Tree(db); Core.Tree subA = root.AddTree("sub-a"); subA.AddFile("empty").Id = aFileId; subA.Id = ow.WriteTree(subA); Core.Tree subB = root.AddTree("sub-b"); subB.AddFile("empty").Id = bFileId; subB.Id = ow.WriteTree(subB); Core.Tree subC = root.AddTree("sub-c"); subC.AddFile("empty").Id = cFileId2; subC.Id = ow.WriteTree(subC); return ow.WriteTree(root); }; var tw = new GitSharp.Core.TreeWalk.TreeWalk(db); tw.reset(new[] { oldTree.Invoke(), newTree.Invoke() }); tw.Recursive = true; tw.setFilter(TreeFilter.ANY_DIFF); Assert.IsTrue(tw.next()); Assert.AreEqual("sub-b/empty", tw.getPathString()); Assert.AreEqual(FileMode.Missing, tw.getFileMode(0)); Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1)); Assert.AreEqual(ObjectId.ZeroId, tw.getObjectId(0)); Assert.AreEqual(bFileId, tw.getObjectId(1)); Assert.IsTrue(tw.next()); Assert.AreEqual("sub-c/empty", tw.getPathString()); Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(0)); Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1)); Assert.AreEqual(cFileId1, tw.getObjectId(0)); Assert.AreEqual(cFileId2, tw.getObjectId(1)); Assert.IsFalse(tw.next()); }
public void testTricky() { Core.Tree tree = new Core.Tree(db); tree.AddFile("a.b"); tree.AddFile("a.c"); tree.AddFile("a/b.b/b"); tree.AddFile("a/b"); tree.AddFile("a/c"); tree.AddFile("a=c"); tree.AddFile("a=d"); TreeIterator i = MakeIterator(tree); Assert.IsTrue(i.hasNext()); Assert.AreEqual("", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a.b", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a.c", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a/b", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a/b.b", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a/b.b/b", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a/c", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a=c", i.next().FullName); Assert.IsTrue(i.hasNext()); Assert.AreEqual("a=d", i.next().FullName); Assert.IsFalse(i.hasNext()); }