public void testBuildThenClear() { DirCache dc = DirCache.read(db); string[] paths = { "a.", "a.b", "a/b", "a0b" }; var ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); } DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); Assert.AreEqual(paths.Length, dc.getEntryCount()); dc.clear(); Assert.AreEqual(0, dc.getEntryCount()); }
public void testBuilderClear() { DirCache dc = DirCache.read(db); string[] paths = { "a.", "a.b", "a/b", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].setFileMode(FileMode.RegularFile); } { DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); } Assert.AreEqual(paths.Length, dc.getEntryCount()); { DirCacheBuilder b = dc.builder(); b.finish(); } Assert.AreEqual(0, dc.getEntryCount()); }
public void testBuildOneFile_FinishWriteCommit() { string path = "a-File-path"; var mode = FileMode.RegularFile; long lastModified = 1218123387057L; int Length = 1342; DirCacheEntry entOrig; DirCache dc = DirCache.Lock(db); DirCacheBuilder b = dc.builder(); Assert.IsNotNull(b); entOrig = new DirCacheEntry(path); entOrig.setFileMode(mode); entOrig.setLastModified(lastModified); entOrig.setLength(Length); Assert.AreNotSame(path, entOrig.getPathString()); Assert.AreEqual(path, entOrig.getPathString()); Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId()); Assert.AreEqual(mode.Bits, entOrig.getRawMode()); Assert.AreEqual(0, entOrig.getStage()); Assert.AreEqual(lastModified, entOrig.getLastModified()); Assert.AreEqual(Length, entOrig.getLength()); Assert.IsFalse(entOrig.isAssumeValid()); b.add(entOrig); b.finish(); Assert.AreEqual(1, dc.getEntryCount()); Assert.AreSame(entOrig, dc.getEntry(0)); dc.write(); Assert.IsTrue(dc.commit()); dc = DirCache.read(db); Assert.AreEqual(1, dc.getEntryCount()); DirCacheEntry entRead = dc.getEntry(0); Assert.AreNotSame(entOrig, entRead); Assert.AreEqual(path, entRead.getPathString()); Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId()); Assert.AreEqual(mode.Bits, entOrig.getRawMode()); Assert.AreEqual(0, entOrig.getStage()); Assert.AreEqual(lastModified, entOrig.getLastModified()); Assert.AreEqual(Length, entOrig.getLength()); Assert.IsFalse(entOrig.isAssumeValid()); }
public void testAdd_ReverseGitSortOrder() { DirCache dc = DirCache.read(db); string[] paths = { "a.", "a.b", "a/b", "a0b" }; DirCacheEntry[] ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].setFileMode(FileMode.RegularFile); } DirCacheBuilder b = dc.builder(); for (int i = ents.Length - 1; i >= 0; i--) { b.add(ents[i]); } b.finish(); Assert.AreEqual(paths.Length, dc.getEntryCount()); for (int i = 0; i < paths.Length; i++) { Assert.AreSame(ents[i], dc.getEntry(i)); Assert.AreEqual(paths[i], dc.getEntry(i).getPathString()); Assert.AreEqual(i, dc.findEntry(paths[i])); Assert.AreSame(ents[i], dc.getEntry(paths[i])); } }
public void testFindSingleFile() { string path = "a-File-path"; DirCache dc = DirCache.read(db); DirCacheBuilder b = dc.builder(); Assert.IsNotNull(b); DirCacheEntry entOrig = new DirCacheEntry(path); entOrig.setFileMode(FileMode.RegularFile); Assert.AreNotSame(path, entOrig.getPathString()); Assert.AreEqual(path, entOrig.getPathString()); b.add(entOrig); b.finish(); Assert.AreEqual(1, dc.getEntryCount()); Assert.AreSame(entOrig, dc.getEntry(0)); Assert.AreEqual(0, dc.findEntry(path)); Assert.AreEqual(-1, dc.findEntry("@@-before")); Assert.AreEqual(0, real(dc.findEntry("@@-before"))); Assert.AreEqual(-2, dc.findEntry("a-zoo")); Assert.AreEqual(1, real(dc.findEntry("a-zoo"))); Assert.AreSame(entOrig, dc.getEntry(path)); }
public virtual void testDF_NoGap() { DirCache tree0 = DirCache.read(db); DirCache tree1 = DirCache.read(db); { DirCacheBuilder b0 = tree0.builder(); DirCacheBuilder b1 = tree1.builder(); b0.add(makeEntry("a", REGULAR_FILE)); b0.add(makeEntry("a.b", EXECUTABLE_FILE)); b1.add(makeEntry("a/b", REGULAR_FILE)); b0.add(makeEntry("a0b", SYMLINK)); b0.finish(); b1.finish(); Assert.AreEqual(3, tree0.getEntryCount()); Assert.AreEqual(1, tree1.getEntryCount()); } NameConflictTreeWalk tw = new NameConflictTreeWalk(db); tw.reset(); tw.addTree(new DirCacheIterator(tree0)); tw.addTree(new DirCacheIterator(tree1)); assertModes("a", REGULAR_FILE, TREE, tw); Assert.IsTrue(tw.isSubtree()); tw.enterSubtree(); assertModes("a/b", MISSING, REGULAR_FILE, tw); assertModes("a.b", EXECUTABLE_FILE, MISSING, tw); assertModes("a0b", SYMLINK, MISSING, tw); }
public void testNoPostOrder() { DirCache tree = DirCache.read(db); { DirCacheBuilder b = tree.builder(); b.add(makeFile("a")); b.add(makeFile("b/c")); b.add(makeFile("b/d")); b.add(makeFile("q")); b.finish(); Assert.AreEqual(4, tree.getEntryCount()); } var tw = new GitSharp.Core.TreeWalk.TreeWalk(db); tw.reset(); tw.PostOrderTraversal = false; tw.addTree(new DirCacheIterator(tree)); assertModes("a", FileMode.RegularFile, tw); assertModes("b", FileMode.Tree, tw); Assert.IsTrue(tw.isSubtree()); Assert.IsFalse(tw.isPostChildren()); tw.enterSubtree(); assertModes("b/c", FileMode.RegularFile, tw); assertModes("b/d", FileMode.RegularFile, tw); assertModes("q", FileMode.RegularFile, tw); }
public void testWriteReadTree() { DirCache dc = DirCache.Lock(db); string A = string.Format("a%2000s", "a"); string B = string.Format("b%2000s", "b"); string[] paths = { A + ".", A + "." + B, A + "/" + B, A + "0" + B }; var ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].setFileMode(FileMode.RegularFile); } DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.commit(); DirCache read = DirCache.read(db); Assert.AreEqual(paths.Length, read.getEntryCount()); Assert.AreEqual(1, read.getCacheTree(true).getChildCount()); }
private void testLongPath(int len) { string longPath = makeLongPath(len); string shortPath = "~~~ shorter-path"; DirCacheEntry longEnt = new DirCacheEntry(longPath); DirCacheEntry shortEnt = new DirCacheEntry(shortPath); Assert.AreEqual(longPath, longEnt.getPathString()); Assert.AreEqual(shortPath, shortEnt.getPathString()); DirCache dc1 = DirCache.Lock(db); DirCacheBuilder b = dc1.builder(); b.add(longEnt); b.add(shortEnt); Assert.IsTrue(b.commit()); Assert.AreEqual(2, dc1.getEntryCount()); Assert.AreSame(longEnt, dc1.getEntry(0)); Assert.AreSame(shortEnt, dc1.getEntry(1)); DirCache dc2 = DirCache.read(db); Assert.AreEqual(2, dc2.getEntryCount()); Assert.AreNotSame(longEnt, dc2.getEntry(0)); Assert.AreEqual(longPath, dc2.getEntry(0).getPathString()); Assert.AreNotSame(shortEnt, dc2.getEntry(1)); Assert.AreEqual(shortPath, dc2.getEntry(1).getPathString()); }
public void testReadIndex_LsFiles() { List <CGitIndexRecord> ls = ReadLsFiles(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(ls.Count, dc.getEntryCount()); int i = 0; foreach (var val in ls) { AssertAreEqual(val, dc.getEntry(i)); i++; } }
public void testUnsupportedOptionalExtension() { var dc = new DirCache(pathOf("gitgit.index.ZZZZ")); dc.read(); Assert.AreEqual(1, dc.getEntryCount()); Assert.AreEqual("A", dc.getEntry(0).getPathString()); }
public void testEmptyTree_NoTreeWalk() { DirCache dc = DirCache.read(db); Assert.AreEqual(0, dc.getEntryCount()); var i = new DirCacheIterator(dc); Assert.IsTrue(i.eof()); }
public void testTwoLevelSubtree() { DirCache dc = DirCache.read(db); string[] paths = { "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].setFileMode(FileMode.RegularFile); } int aFirst = 1; int aLast = 4; int acFirst = 2; int acLast = 3; DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); Assert.IsNull(dc.getCacheTree(false)); DirCacheTree root = dc.getCacheTree(true); Assert.IsNotNull(root); Assert.AreSame(root, dc.getCacheTree(true)); Assert.AreEqual(string.Empty, root.getNameString()); Assert.AreEqual(string.Empty, root.getPathString()); Assert.AreEqual(1, root.getChildCount()); Assert.AreEqual(dc.getEntryCount(), root.getEntrySpan()); Assert.IsFalse(root.isValid()); DirCacheTree aTree = root.getChild(0); Assert.IsNotNull(aTree); Assert.AreSame(aTree, root.getChild(0)); Assert.AreEqual("a", aTree.getNameString()); Assert.AreEqual("a/", aTree.getPathString()); Assert.AreEqual(1, aTree.getChildCount()); Assert.AreEqual(aLast - aFirst + 1, aTree.getEntrySpan()); Assert.IsFalse(aTree.isValid()); DirCacheTree acTree = aTree.getChild(0); Assert.IsNotNull(acTree); Assert.AreSame(acTree, aTree.getChild(0)); Assert.AreEqual("c", acTree.getNameString()); Assert.AreEqual("a/c/", acTree.getPathString()); Assert.AreEqual(0, acTree.getChildCount()); Assert.AreEqual(acLast - acFirst + 1, acTree.getEntrySpan()); Assert.IsFalse(acTree.isValid()); }
public void testReadIndex_DirCacheTree() { List <CGitIndexRecord> cList = ReadLsFiles(); List <CGitLsTreeRecord> cTree = ReadLsTree(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(cList.Count, dc.getEntryCount()); DirCacheTree jTree = dc.getCacheTree(false); Assert.IsNotNull(jTree); Assert.AreEqual(string.Empty, jTree.getNameString()); Assert.AreEqual(string.Empty, jTree.getPathString()); Assert.IsTrue(jTree.isValid()); Assert.AreEqual(ObjectId .FromString("698dd0b8d0c299f080559a1cffc7fe029479a408"), jTree .getObjectId()); Assert.AreEqual(cList.Count, jTree.getEntrySpan()); var subtrees = new List <CGitLsTreeRecord>(); foreach (CGitLsTreeRecord r in cTree) { if (FileMode.Tree.Equals(r.Mode)) { subtrees.Add(r); } } Assert.AreEqual(subtrees.Count, jTree.getChildCount()); for (int i = 0; i < jTree.getChildCount(); i++) { DirCacheTree sj = jTree.getChild(i); CGitLsTreeRecord sc = subtrees[i]; Assert.AreEqual(sc.Path, sj.getNameString()); Assert.AreEqual(sc.Path + "/", sj.getPathString()); Assert.IsTrue(sj.isValid()); Assert.AreEqual(sc.Id, sj.getObjectId()); } }
public void testEntriesWithin() { DirCache dc = DirCache.read(db); string[] paths = { "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].setFileMode(FileMode.RegularFile); } int aFirst = 1; int aLast = 3; DirCacheBuilder b = dc.builder(); for (int i = 0; i < ents.Length; i++) { b.add(ents[i]); } b.finish(); Assert.AreEqual(paths.Length, dc.getEntryCount()); for (int i = 0; i < ents.Length; i++) { Assert.AreSame(ents[i], dc.getEntry(i)); } DirCacheEntry[] aContents = dc.getEntriesWithin("a"); Assert.IsNotNull(aContents); Assert.AreEqual(aLast - aFirst + 1, aContents.Length); for (int i = aFirst, j = 0; i <= aLast; i++, j++) { Assert.AreSame(ents[i], aContents[j]); } aContents = dc.getEntriesWithin("a/"); Assert.IsNotNull(aContents); Assert.AreEqual(aLast - aFirst + 1, aContents.Length); for (int i = aFirst, j = 0; i <= aLast; i++, j++) { Assert.AreSame(ents[i], aContents[j]); } Assert.IsNotNull(dc.getEntriesWithin("a.")); Assert.AreEqual(0, dc.getEntriesWithin("a.").Length); Assert.IsNotNull(dc.getEntriesWithin("a0b")); Assert.AreEqual(0, dc.getEntriesWithin("a0b.").Length); Assert.IsNotNull(dc.getEntriesWithin("zoo")); Assert.AreEqual(0, dc.getEntriesWithin("zoo.").Length); }
public void testReadMissing_TempIndex() { var idx = new FileInfo(db.Directory + "/tmp_index"); Assert.IsFalse(File.Exists(idx.FullName)); DirCache dc = DirCache.read(idx); Assert.IsNotNull(dc); Assert.AreEqual(0, dc.getEntryCount()); }
public void testEmptyTree_WithTreeWalk() { DirCache dc = DirCache.read(db); Assert.AreEqual(0, dc.getEntryCount()); var tw = new TreeWalk(db); tw.reset(); tw.addTree(new DirCacheIterator(dc)); Assert.IsFalse(tw.next()); }
public void testPathFilterGroup_DoesNotSkipTail() { DirCache dc = DirCache.read(db); var mode = FileMode.RegularFile; string[] paths = { "a.", "a/b", "a/c", "a/d", "a0b" }; var ents = new DirCacheEntry[paths.Length]; for (int i = 0; i < paths.Length; i++) { ents[i] = new DirCacheEntry(paths[i]); ents[i].setFileMode(mode); } DirCacheBuilder builder = dc.builder(); for (int i = 0; i < ents.Length; i++) { builder.add(ents[i]); } builder.finish(); const int expIdx = 2; DirCacheBuilder b = dc.builder(); var tw = new GitSharp.Core.TreeWalk.TreeWalk(db); tw.reset(); tw.addTree(new DirCacheBuildIterator(b)); tw.Recursive = true; tw.setFilter(PathFilterGroup.createFromStrings(new[] { paths[expIdx] })); Assert.IsTrue(tw.next(), "found " + paths[expIdx]); var c = tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator)); Assert.IsNotNull(c); Assert.AreEqual(expIdx, c.Pointer); Assert.AreSame(ents[expIdx], c.getDirCacheEntry()); Assert.AreEqual(paths[expIdx], tw.getPathString()); Assert.AreEqual(mode.Bits, tw.getRawMode(0)); Assert.AreSame(mode, tw.getFileMode(0)); b.add(c.getDirCacheEntry()); Assert.IsFalse(tw.next(), "no more entries"); b.finish(); Assert.AreEqual(ents.Length, dc.getEntryCount()); for (int i = 0; i < ents.Length; i++) { Assert.AreSame(ents[i], dc.getEntry(i)); } }
public void testBuildEmpty() { DirCache dc = DirCache.Lock(db); DirCacheBuilder b = dc.builder(); Assert.IsNotNull(b); b.finish(); dc.write(); Assert.IsTrue(dc.commit()); dc = DirCache.read(db); Assert.AreEqual(0, dc.getEntryCount()); }
public void testTreeWalk_LsFiles() { List <CGitIndexRecord> ls = ReadLsFiles(); var dc = new DirCache(_index); Assert.AreEqual(0, dc.getEntryCount()); dc.read(); Assert.AreEqual(ls.Count, dc.getEntryCount()); var rItr = ls.GetEnumerator(); var tw = new GitSharp.Core.TreeWalk.TreeWalk(db); tw.reset(); tw.Recursive = true; tw.addTree(new DirCacheIterator(dc)); while (rItr.MoveNext()) { Assert.IsTrue(tw.next()); var dcItr = tw.getTree <DirCacheIterator>(0, typeof(DirCacheIterator)); Assert.IsNotNull(dcItr); AssertAreEqual(rItr.Current, dcItr.getDirCacheEntry()); } }
public void testWriteEmptyReadEmpty_RealIndex() { var idx = new FileInfo(db.Directory + "/index"); var lck = new FileInfo(db.Directory + "/index.lock"); Assert.IsFalse(File.Exists(idx.FullName)); Assert.IsFalse(File.Exists(lck.FullName)); DirCache dc = DirCache.Lock(db); dc.write(); Assert.IsTrue(dc.commit()); Assert.IsTrue(File.Exists(idx.FullName)); dc = DirCache.read(db); Assert.AreEqual(0, dc.getEntryCount()); }
public void testLockMissing_TempIndex() { var idx = new FileInfo(db.Directory + "/tmp_index"); var lck = new FileInfo(db.Directory + "/tmp_index.lock"); Assert.IsFalse(File.Exists(idx.FullName)); Assert.IsFalse(File.Exists(lck.FullName)); DirCache dc = DirCache.Lock(idx); Assert.IsNotNull(dc); Assert.IsFalse(File.Exists(idx.FullName)); Assert.IsTrue(File.Exists(lck.FullName)); Assert.AreEqual(0, dc.getEntryCount()); dc.unlock(); Assert.IsFalse(File.Exists(idx.FullName)); Assert.IsFalse(File.Exists(lck.FullName)); }
internal void Apply(Stash stash) { Commit wip = _repo.Get <Commit> (stash.CommitId); Commit index = wip.Parents.Last(); Tree wipTree = wip.Tree; Tree headTree = _repo.CurrentBranch.CurrentCommit.Tree; GitIndex currentIndex = _repo.Index.GitIndex; Tree currentIndexTree = new Tree(_repo, _repo._internal_repo.MapTree(currentIndex.writeTree())); WorkDirCheckout co = new WorkDirCheckout(_repo._internal_repo, _repo._internal_repo.WorkingDirectory, headTree.InternalTree, currentIndex, wip.Tree.InternalTree); co.checkout(); currentIndex.write(); List <DirCacheEntry> toAdd = new List <DirCacheEntry> (); DirCache dc = DirCache.Lock(_repo._internal_repo); try { var cacheEditor = dc.editor(); // The WorkDirCheckout class doesn't check if there are conflicts in modified files, // so we have to do it here. foreach (var c in co.Updated) { var baseEntry = wip.Parents.First().Tree[c.Key] as Leaf; var oursEntry = wipTree [c.Key] as Leaf; var theirsEntry = headTree [c.Key] as Leaf; if (baseEntry != null && oursEntry != null && currentIndexTree [c.Key] == null) { // If a file was reported as updated but that file is not present in the stashed index, // it means that the file was scheduled to be deleted. cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key)); File.Delete(_repo.FromGitPath(c.Key)); } else if (baseEntry != null && oursEntry != null && theirsEntry != null) { MergeResult res = MergeAlgorithm.merge(new RawText(baseEntry.RawData), new RawText(oursEntry.RawData), new RawText(theirsEntry.RawData)); MergeFormatter f = new MergeFormatter(); using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(_repo.FromGitPath(c.Key)))) { f.formatMerge(bw, res, "Base", "Stash", "Head", Constants.CHARSET.WebName); } if (res.containsConflicts()) { // Remove the entry from the index. It will be added later on. cacheEditor.@add(new DirCacheEditor.DeletePath(c.Key)); // Generate index entries for each merge stage // Those entries can't be added right now to the index because a DirCacheEditor // can't be used at the same time as a DirCacheBuilder. var e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_1); e.setObjectId(baseEntry.InternalEntry.Id); e.setFileMode(baseEntry.InternalEntry.Mode); toAdd.Add(e); e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_2); e.setObjectId(oursEntry.InternalEntry.Id); e.setFileMode(oursEntry.InternalEntry.Mode); toAdd.Add(e); e = new DirCacheEntry(c.Key, DirCacheEntry.STAGE_3); e.setObjectId(theirsEntry.InternalEntry.Id); e.setFileMode(theirsEntry.InternalEntry.Mode); toAdd.Add(e); } } } cacheEditor.finish(); if (toAdd.Count > 0) { // Add the index entries generated above var cacheBuilder = dc.builder(); for (int n = 0; n < dc.getEntryCount(); n++) { cacheBuilder.@add(dc.getEntry(n)); } foreach (var entry in toAdd) { cacheBuilder.@add(entry); } cacheBuilder.finish(); } dc.write(); dc.commit(); } catch { dc.unlock(); throw; } }