public virtual void TestIsModifiedFileSmudged() { FilePath f = WriteTrashFile("file", "content"); Git git = new Git(db); // The idea of this test is to check the smudged handling // Hopefully fsTick will make sure our entry gets smudged FsTick(f); WriteTrashFile("file", "content"); git.Add().AddFilepattern("file").Call(); WriteTrashFile("file", "conten2"); DirCacheEntry dce = db.ReadDirCache().GetEntry("file"); FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig )db.GetConfig()).Get(WorkingTreeOptions.KEY)); while (!fti.EntryPathString.Equals("file")) { fti.Next(1); } // If the fsTick trick does not work we could skip the compareMetaData // test and hope that we are usually testing the intended code path. NUnit.Framework.Assert.AreEqual(WorkingTreeIterator.MetadataDiff.SMUDGED, fti.CompareMetadata (dce)); NUnit.Framework.Assert.IsTrue(fti.IsModified(dce, false)); }
public virtual void TestSimpleIterate() { FileTreeIterator top = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig )db.GetConfig()).Get(WorkingTreeOptions.KEY)); NUnit.Framework.Assert.IsTrue(top.First); NUnit.Framework.Assert.IsFalse(top.Eof); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode); NUnit.Framework.Assert.AreEqual(paths[0], NameOf(top)); NUnit.Framework.Assert.AreEqual(paths[0].Length, top.GetEntryLength()); NUnit.Framework.Assert.AreEqual(mtime[0], top.GetEntryLastModified()); top.Next(1); NUnit.Framework.Assert.IsFalse(top.First); NUnit.Framework.Assert.IsFalse(top.Eof); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode); NUnit.Framework.Assert.AreEqual(paths[1], NameOf(top)); NUnit.Framework.Assert.AreEqual(paths[1].Length, top.GetEntryLength()); NUnit.Framework.Assert.AreEqual(mtime[1], top.GetEntryLastModified()); top.Next(1); NUnit.Framework.Assert.IsFalse(top.First); NUnit.Framework.Assert.IsFalse(top.Eof); NUnit.Framework.Assert.AreEqual(FileMode.TREE.GetBits(), top.mode); ObjectReader reader = db.NewObjectReader(); AbstractTreeIterator sub = top.CreateSubtreeIterator(reader); NUnit.Framework.Assert.IsTrue(sub is FileTreeIterator); FileTreeIterator subfti = (FileTreeIterator)sub; NUnit.Framework.Assert.IsTrue(sub.First); NUnit.Framework.Assert.IsFalse(sub.Eof); NUnit.Framework.Assert.AreEqual(paths[2], NameOf(sub)); NUnit.Framework.Assert.AreEqual(paths[2].Length, subfti.GetEntryLength()); NUnit.Framework.Assert.AreEqual(mtime[2], subfti.GetEntryLastModified()); sub.Next(1); NUnit.Framework.Assert.IsTrue(sub.Eof); top.Next(1); NUnit.Framework.Assert.IsFalse(top.First); NUnit.Framework.Assert.IsFalse(top.Eof); NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE.GetBits(), top.mode); NUnit.Framework.Assert.AreEqual(paths[3], NameOf(top)); NUnit.Framework.Assert.AreEqual(paths[3].Length, top.GetEntryLength()); NUnit.Framework.Assert.AreEqual(mtime[3], top.GetEntryLastModified()); top.Next(1); NUnit.Framework.Assert.IsTrue(top.Eof); }
public virtual void TestIsModifiedSymlink() { FilePath f = WriteTrashFile("symlink", "content"); Git git = new Git(db); git.Add().AddFilepattern("symlink").Call(); git.Commit().SetMessage("commit").Call(); // Modify previously committed DirCacheEntry and write it back to disk DirCacheEntry dce = db.ReadDirCache().GetEntry("symlink"); dce.FileMode = FileMode.SYMLINK; DirCacheCheckout.CheckoutEntry(db, f, dce); FileTreeIterator fti = new FileTreeIterator(trash, db.FileSystem, ((FileBasedConfig )db.GetConfig()).Get(WorkingTreeOptions.KEY)); while (!fti.EntryPathString.Equals("symlink")) { fti.Next(1); } NUnit.Framework.Assert.IsFalse(fti.IsModified(dce, false)); }
/// <summary>Resets the index to represent exactly some filesystem content.</summary> /// <remarks> /// Resets the index to represent exactly some filesystem content. E.g. the /// following call will replace the index with the working tree content: /// <p> /// <code>resetIndex(new FileSystemIterator(db))</code> /// <p> /// This method can be used by testcases which first prepare a new commit /// somewhere in the filesystem (e.g. in the working-tree) and then want to /// have an index which matches their prepared content. /// </remarks> /// <param name="treeItr"> /// a /// <see cref="NGit.Treewalk.FileTreeIterator">NGit.Treewalk.FileTreeIterator</see> /// which determines which files should /// go into the new index /// </param> /// <exception cref="System.IO.FileNotFoundException">System.IO.FileNotFoundException /// </exception> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> protected internal virtual void ResetIndex(FileTreeIterator treeItr) { ObjectInserter inserter = db.NewObjectInserter(); DirCacheBuilder builder = db.LockDirCache().Builder(); DirCacheEntry dce; while (!treeItr.Eof) { long len = treeItr.GetEntryLength(); dce = new DirCacheEntry(treeItr.EntryPathString); dce.FileMode = treeItr.EntryFileMode; dce.LastModified = treeItr.GetEntryLastModified(); dce.SetLength((int)len); FileInputStream @in = new FileInputStream(treeItr.GetEntryFile()); dce.SetObjectId(inserter.Insert(Constants.OBJ_BLOB, len, @in)); @in.Close(); builder.Add(dce); treeItr.Next(1); } builder.Commit(); inserter.Flush(); inserter.Release(); }
IEnumerable<string> GetDirectoryFiles (DirectoryInfo dir) { FileTreeIterator iter = new FileTreeIterator (dir.FullName, RootRepository.FileSystem, WorkingTreeOptions.KEY.Parse(RootRepository.GetConfig())); while (!iter.Eof) { var file = iter.GetEntryFile (); if (file != null && !iter.IsEntryIgnored ()) yield return file.GetPath (); iter.Next (1); } }