public virtual void TestEmptyTree_NoTreeWalk() { DirCache dc = DirCache.NewInCore(); NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount()); DirCacheIterator i = new DirCacheIterator(dc); NUnit.Framework.Assert.IsTrue(i.Eof); }
public virtual void TestNoSubtree_NoTreeWalk() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); int pathIdx = 0; for (; !i_2.Eof; i_2.Next(1)) { NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry()); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
public virtual void TestEmptyTree_NoTreeWalk() { DirCache dc = DirCache.NewInCore(); NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount()); DirCacheIterator i = new DirCacheIterator(dc); NUnit.Framework.Assert.IsTrue(i.Eof); }
internal DirCacheIterator(NGit.Dircache.DirCacheIterator p, DirCacheTree dct) : base (p, p.path, p.pathLen + 1) { cache = p.cache; tree = dct; treeStart = p.ptr; treeEnd = treeStart + tree.GetEntrySpan(); subtreeId = p.subtreeId; ptr = p.ptr; ParseEntry(); }
/// <summary>Update any smudged entries with information from the working tree.</summary> /// <remarks>Update any smudged entries with information from the working tree.</remarks> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> private void UpdateSmudgedEntries() { TreeWalk walk = new TreeWalk(repository); IList <string> paths = new AList <string>(128); try { for (int i = 0; i < entryCnt; i++) { if (sortedEntries[i].IsSmudged) { paths.AddItem(sortedEntries[i].PathString); } } if (paths.IsEmpty()) { return; } walk.Filter = PathFilterGroup.CreateFromStrings(paths); DirCacheIterator iIter = new DirCacheIterator(this); FileTreeIterator fIter = new FileTreeIterator(repository); walk.AddTree(iIter); walk.AddTree(fIter); walk.Recursive = true; while (walk.Next()) { iIter = walk.GetTree <DirCacheIterator>(0); if (iIter == null) { continue; } fIter = walk.GetTree <FileTreeIterator>(1); if (fIter == null) { continue; } DirCacheEntry entry = iIter.GetDirCacheEntry(); if (entry.IsSmudged && iIter.IdEqual(fIter)) { entry.SetLength(fIter.GetEntryLength()); entry.LastModified = fIter.GetEntryLastModified(); } } } finally { walk.Release(); } }
public virtual void TestSingleSubtree_NoRecursion() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a/b", "a/c", "a/d", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); string[] expPaths = new string[] { "a.", "a", "a0b" }; FileMode[] expModes = new FileMode[] { FileMode.REGULAR_FILE, FileMode.TREE, FileMode .REGULAR_FILE }; int[] expPos = new int[] { 0, -1, 4 }; DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); tw.Recursive = false; int pathIdx = 0; while (tw.Next()) { NUnit.Framework.Assert.AreSame(i_2, tw.GetTree <DirCacheIterator>(0)); NUnit.Framework.Assert.AreEqual(expModes[pathIdx].GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(expModes[pathIdx], tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(expPaths[pathIdx], tw.PathString); if (expPos[pathIdx] >= 0) { NUnit.Framework.Assert.AreEqual(expPos[pathIdx], i_2.ptr); NUnit.Framework.Assert.AreSame(ents[expPos[pathIdx]], i_2.GetDirCacheEntry()); } else { NUnit.Framework.Assert.AreSame(FileMode.TREE, tw.GetFileMode(0)); } pathIdx++; } NUnit.Framework.Assert.AreEqual(expPaths.Length, pathIdx); }
public virtual void TestPathFilterGroup_DoesNotSkipTail() { DirCache dc = db.ReadDirCache(); FileMode mode = FileMode.REGULAR_FILE; string[] paths = new string[] { "a.", "a/b", "a/c", "a/d", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = mode; } { DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); } int expIdx = 2; DirCacheBuilder b_1 = dc.Builder(); TreeWalk tw = new TreeWalk(db); tw.AddTree(new DirCacheBuildIterator(b_1)); tw.Recursive = true; tw.Filter = PathFilterGroup.CreateFromStrings(Collections.Singleton(paths[expIdx] )); NUnit.Framework.Assert.IsTrue(tw.Next(), "found " + paths[expIdx]); DirCacheIterator c = tw.GetTree <DirCacheIterator>(0); NUnit.Framework.Assert.IsNotNull(c); NUnit.Framework.Assert.AreEqual(expIdx, c.ptr); NUnit.Framework.Assert.AreSame(ents[expIdx], c.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[expIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0)); b_1.Add(c.GetDirCacheEntry()); NUnit.Framework.Assert.IsFalse(tw.Next(), "no more entries"); b_1.Finish(); NUnit.Framework.Assert.AreEqual(ents.Length, dc.GetEntryCount()); for (int i_2 = 0; i_2 < ents.Length; i_2++) { NUnit.Framework.Assert.AreSame(ents[i_2], dc.GetEntry(i_2)); } }
public virtual void TestDiff() { Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test"); FilePath folder = new FilePath(db.Directory.GetParent(), "folder"); folder.Mkdir(); Write(new FilePath(folder, "folder.txt"), "folder"); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "folder change"); PatchIdDiffFormatter df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df.GetCalulatedPatchId ().Name); }
public virtual void TestTwoLevelSubtree_FilterPath() { DirCache dc = DirCache.NewInCore(); FileMode mode = FileMode.REGULAR_FILE; string[] paths = new string[] { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = mode; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); TreeWalk tw = new TreeWalk(db); for (int victimIdx = 0; victimIdx < paths.Length; victimIdx++) { tw.Reset(); tw.AddTree(new DirCacheIterator(dc)); tw.Filter = PathFilterGroup.CreateFromStrings(Collections.Singleton(paths[victimIdx ])); tw.Recursive = tw.Filter.ShouldBeRecursive(); NUnit.Framework.Assert.IsTrue(tw.Next()); DirCacheIterator c = tw.GetTree <DirCacheIterator>(0); NUnit.Framework.Assert.IsNotNull(c); NUnit.Framework.Assert.AreEqual(victimIdx, c.ptr); NUnit.Framework.Assert.AreSame(ents[victimIdx], c.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[victimIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0)); NUnit.Framework.Assert.IsFalse(tw.Next()); } }
public virtual void TestSingleSubtree_Recursive() { DirCache dc = DirCache.NewInCore(); FileMode mode = FileMode.REGULAR_FILE; string[] paths = new string[] { "a.", "a/b", "a/c", "a/d", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = mode; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); tw.Recursive = true; int pathIdx = 0; while (tw.Next()) { DirCacheIterator c = tw.GetTree <DirCacheIterator>(0); NUnit.Framework.Assert.IsNotNull(c); NUnit.Framework.Assert.AreEqual(pathIdx, c.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], c.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0)); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
public virtual void TestNoSubtree_WithTreeWalk() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a0b" }; FileMode[] modes = new FileMode[] { FileMode.EXECUTABLE_FILE, FileMode.GITLINK }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = modes[i]; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); int pathIdx = 0; while (tw.Next()) { NUnit.Framework.Assert.AreSame(i_2, tw.GetTree <DirCacheIterator>(0)); NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(modes[pathIdx].GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(modes[pathIdx], tw.GetFileMode(0)); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
public virtual void TestSameDiff() { Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test"); FilePath folder = new FilePath(db.Directory.GetParent(), "folder"); folder.Mkdir(); Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder"); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "\n\n\n\nfolder change"); PatchIdDiffFormatter df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId ().Name); Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder"); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "a\n\n\n\nfolder change"); df = new PatchIdDiffFormatter(); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); oldTree = new DirCacheIterator(db.ReadDirCache()); newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); NUnit.Framework.Assert.AreEqual("08fca5ac531383eb1da8bf6b6f7cf44411281407", df.GetCalulatedPatchId ().Name); }
public virtual void TestNoSubtree_NoTreeWalk() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); int pathIdx = 0; for (; !i_2.Eof; i_2.Next(1)) { NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry()); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
public virtual void TestSingleSubtree_NoRecursion() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a/b", "a/c", "a/d", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = FileMode.REGULAR_FILE; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); string[] expPaths = new string[] { "a.", "a", "a0b" }; FileMode[] expModes = new FileMode[] { FileMode.REGULAR_FILE, FileMode.TREE, FileMode .REGULAR_FILE }; int[] expPos = new int[] { 0, -1, 4 }; DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); tw.Recursive = false; int pathIdx = 0; while (tw.Next()) { NUnit.Framework.Assert.AreSame(i_2, tw.GetTree<DirCacheIterator>(0)); NUnit.Framework.Assert.AreEqual(expModes[pathIdx].GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(expModes[pathIdx], tw.GetFileMode(0)); NUnit.Framework.Assert.AreEqual(expPaths[pathIdx], tw.PathString); if (expPos[pathIdx] >= 0) { NUnit.Framework.Assert.AreEqual(expPos[pathIdx], i_2.ptr); NUnit.Framework.Assert.AreSame(ents[expPos[pathIdx]], i_2.GetDirCacheEntry()); } else { NUnit.Framework.Assert.AreSame(FileMode.TREE, tw.GetFileMode(0)); } pathIdx++; } NUnit.Framework.Assert.AreEqual(expPaths.Length, pathIdx); }
public virtual void TestSingleSubtree_Recursive() { DirCache dc = DirCache.NewInCore(); FileMode mode = FileMode.REGULAR_FILE; string[] paths = new string[] { "a.", "a/b", "a/c", "a/d", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = mode; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); tw.Recursive = true; int pathIdx = 0; while (tw.Next()) { DirCacheIterator c = tw.GetTree<DirCacheIterator>(0); NUnit.Framework.Assert.IsNotNull(c); NUnit.Framework.Assert.AreEqual(pathIdx, c.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], c.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0)); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
public virtual void TestDiff() { Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test"); FilePath folder = new FilePath(db.Directory.GetParent(), "folder"); folder.Mkdir(); Write(new FilePath(folder, "folder.txt"), "folder"); Git git = new Git(db); git.Add().AddFilepattern(".").Call(); git.Commit().SetMessage("Initial commit").Call(); Write(new FilePath(folder, "folder.txt"), "folder change"); ByteArrayOutputStream os = new ByteArrayOutputStream(); DiffFormatter df = new DiffFormatter(new BufferedOutputStream(os)); df.SetRepository(db); df.SetPathFilter(PathFilter.Create("folder")); DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator newTree = new FileTreeIterator(db); df.Format(oldTree, newTree); df.Flush(); string actual = os.ToString(); string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n" + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" + "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n"; NUnit.Framework.Assert.AreEqual(expected.ToString(), actual); }
public virtual void TestNoSubtree_WithTreeWalk() { DirCache dc = DirCache.NewInCore(); string[] paths = new string[] { "a.", "a0b" }; FileMode[] modes = new FileMode[] { FileMode.EXECUTABLE_FILE, FileMode.GITLINK }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].FileMode = modes[i]; } DirCacheBuilder b = dc.Builder(); for (int i_1 = 0; i_1 < ents.Length; i_1++) { b.Add(ents[i_1]); } b.Finish(); DirCacheIterator i_2 = new DirCacheIterator(dc); TreeWalk tw = new TreeWalk(db); tw.AddTree(i_2); int pathIdx = 0; while (tw.Next()) { NUnit.Framework.Assert.AreSame(i_2, tw.GetTree<DirCacheIterator>(0)); NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr); NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry()); NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString); NUnit.Framework.Assert.AreEqual(modes[pathIdx].GetBits(), tw.GetRawMode(0)); NUnit.Framework.Assert.AreSame(modes[pathIdx], tw.GetFileMode(0)); pathIdx++; } NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx); }
public virtual void IdOffset() { Git git = new Git(db); WriteTrashFile("fileAinfsonly", "A"); FilePath fileBinindex = WriteTrashFile("fileBinindex", "B"); FsTick(fileBinindex); git.Add().AddFilepattern("fileBinindex").Call(); WriteTrashFile("fileCinfsonly", "C"); TreeWalk tw = new TreeWalk(db); DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator workTreeIter = new FileTreeIterator(db); tw.AddTree(indexIter); tw.AddTree(workTreeIter); workTreeIter.SetDirCacheIterator(tw, 0); AssertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw); AssertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw); AssertEntry("0000000000000000000000000000000000000000", "a", tw); AssertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw); // The reason for adding this test. Check that the id is correct for // mixed AssertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220", "fileAinfsonly", tw); AssertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex", tw); AssertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c", "fileCinfsonly", tw); NUnit.Framework.Assert.IsFalse(tw.Next()); }
public virtual void SubmoduleNestedWithHeadMatchingIndex() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); RevCommit id = git.Commit().SetMessage("create file").Call(); string path = "sub/dir1/dir2"; DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_412(id, path)); editor.Commit(); Git.CloneRepository().SetURI(db.Directory.ToURI().ToString()).SetDirectory(new FilePath (db.WorkTree, path)).Call().GetRepository().Close(); TreeWalk walk = new TreeWalk(db); DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator workTreeIter = new FileTreeIterator(db); walk.AddTree(indexIter); walk.AddTree(workTreeIter); walk.Filter = PathFilter.Create(path); NUnit.Framework.Assert.IsTrue(walk.Next()); NUnit.Framework.Assert.IsTrue(indexIter.IdEqual(workTreeIter)); }
public virtual void SubmoduleWithNoHead() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); RevCommit id = git.Commit().SetMessage("create file").Call(); string path = "sub"; DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_345(id, path)); editor.Commit(); NUnit.Framework.Assert.IsNotNull(Git.Init().SetDirectory(new FilePath(db.WorkTree , path)).Call().GetRepository()); TreeWalk walk = new TreeWalk(db); DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator workTreeIter = new FileTreeIterator(db); walk.AddTree(indexIter); walk.AddTree(workTreeIter); walk.Filter = PathFilter.Create(path); NUnit.Framework.Assert.IsTrue(walk.Next()); NUnit.Framework.Assert.IsFalse(indexIter.IdEqual(workTreeIter)); NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, workTreeIter.EntryObjectId); }
public virtual void TestDirCacheMatchingId() { FilePath f = WriteTrashFile("file", "content"); Git git = new Git(db); WriteTrashFile("file", "content"); FsTick(f); git.Add().AddFilepattern("file").Call(); DirCacheEntry dce = db.ReadDirCache().GetEntry("file"); TreeWalk tw = new TreeWalk(db); FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig )db.GetConfig()).Get(WorkingTreeOptions.KEY)); tw.AddTree(fti); DirCacheIterator dci = new DirCacheIterator(db.ReadDirCache()); tw.AddTree(dci); fti.SetDirCacheIterator(tw, 1); while (tw.Next() && !tw.PathString.Equals("file")) { } // NUnit.Framework.Assert.AreEqual(WorkingTreeIterator.MetadataDiff.EQUAL, fti.CompareMetadata (dce)); ObjectId fromRaw = ObjectId.FromRaw(fti.IdBuffer, fti.IdOffset); NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", fromRaw .GetName()); NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false)); }
public virtual void SubmoduleDirectoryIterator() { Git git = new Git(db); WriteTrashFile("file.txt", "content"); git.Add().AddFilepattern("file.txt").Call(); RevCommit id = git.Commit().SetMessage("create file").Call(); string path = "sub"; DirCache cache = db.LockDirCache(); DirCacheEditor editor = cache.Editor(); editor.Add(new _PathEdit_326(id, path)); editor.Commit(); Git.CloneRepository().SetURI(db.Directory.ToURI().ToString()).SetDirectory(new FilePath (db.WorkTree, path)).Call(); TreeWalk walk = new TreeWalk(db); DirCacheIterator indexIter = new DirCacheIterator(db.ReadDirCache()); FileTreeIterator workTreeIter = new FileTreeIterator(db.WorkTree, db.FileSystem, ((FileBasedConfig)db.GetConfig()).Get(WorkingTreeOptions.KEY)); walk.AddTree(indexIter); walk.AddTree(workTreeIter); walk.Filter = PathFilter.Create(path); NUnit.Framework.Assert.IsTrue(walk.Next()); NUnit.Framework.Assert.IsTrue(indexIter.IdEqual(workTreeIter)); }