public virtual void TestUpdateSmudgedEntries() { git.BranchCreate().SetName("test2").Call(); RefUpdate rup = db.UpdateRef(Constants.HEAD); rup.Link("refs/heads/test2"); FilePath file = new FilePath(db.WorkTree, "Test.txt"); long size = file.Length(); long mTime = file.LastModified() - 5000L; NUnit.Framework.Assert.IsTrue(file.SetLastModified(mTime)); DirCache cache = DirCache.Lock(db.GetIndexFile(), db.FileSystem); DirCacheEntry entry = cache.GetEntry("Test.txt"); NUnit.Framework.Assert.IsNotNull(entry); entry.SetLength(0); entry.LastModified = 0; cache.Write(); NUnit.Framework.Assert.IsTrue(cache.Commit()); cache = DirCache.Read(db.GetIndexFile(), db.FileSystem); entry = cache.GetEntry("Test.txt"); NUnit.Framework.Assert.IsNotNull(entry); NUnit.Framework.Assert.AreEqual(0, entry.Length); NUnit.Framework.Assert.AreEqual(0, entry.LastModified); db.GetIndexFile().SetLastModified(db.GetIndexFile().LastModified() - 5000); NUnit.Framework.Assert.IsNotNull(git.Checkout().SetName("test").Call()); cache = DirCache.Read(db.GetIndexFile(), db.FileSystem); entry = cache.GetEntry("Test.txt"); NUnit.Framework.Assert.IsNotNull(entry); NUnit.Framework.Assert.AreEqual(size, entry.Length); NUnit.Framework.Assert.AreEqual(mTime, entry.LastModified); }
public virtual void TestCherryPickOverExecutableChangeOnNonExectuableFileSystem() { Git git = new Git(db); FilePath file = WriteTrashFile("test.txt", "a"); NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("test.txt").Call()); NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("commit1").Call()); NUnit.Framework.Assert.IsNotNull(git.Checkout().SetCreateBranch(true).SetName("a" ).Call()); WriteTrashFile("test.txt", "b"); NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("test.txt").Call()); RevCommit commit2 = git.Commit().SetMessage("commit2").Call(); NUnit.Framework.Assert.IsNotNull(commit2); NUnit.Framework.Assert.IsNotNull(git.Checkout().SetName(Constants.MASTER).Call()); DirCache cache = db.LockDirCache(); cache.GetEntry("test.txt").FileMode = FileMode.EXECUTABLE_FILE; cache.Write(); NUnit.Framework.Assert.IsTrue(cache.Commit()); cache.Unlock(); NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("commit3").Call()); git.GetRepository().GetConfig().SetBoolean(ConfigConstants.CONFIG_CORE_SECTION, null , ConfigConstants.CONFIG_KEY_FILEMODE, false); CherryPickResult result = git.CherryPick().Include(commit2).Call(); NUnit.Framework.Assert.IsNotNull(result); NUnit.Framework.Assert.AreEqual(CherryPickResult.CherryPickStatus.OK, result.GetStatus ()); }
public virtual void CommitUpdatesSmudgedEntries() { Git git = new Git(db); FilePath file1 = WriteTrashFile("file1.txt", "content1"); NUnit.Framework.Assert.IsTrue(file1.SetLastModified(file1.LastModified() - 5000)); FilePath file2 = WriteTrashFile("file2.txt", "content2"); NUnit.Framework.Assert.IsTrue(file2.SetLastModified(file2.LastModified() - 5000)); FilePath file3 = WriteTrashFile("file3.txt", "content3"); NUnit.Framework.Assert.IsTrue(file3.SetLastModified(file3.LastModified() - 5000)); NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("file1.txt").AddFilepattern ("file2.txt").AddFilepattern("file3.txt").Call()); RevCommit commit = git.Commit().SetMessage("add files").Call(); NUnit.Framework.Assert.IsNotNull(commit); DirCache cache = DirCache.Read(db.GetIndexFile(), db.FileSystem); int file1Size = cache.GetEntry("file1.txt").Length; int file2Size = cache.GetEntry("file2.txt").Length; int file3Size = cache.GetEntry("file3.txt").Length; ObjectId file2Id = cache.GetEntry("file2.txt").GetObjectId(); ObjectId file3Id = cache.GetEntry("file3.txt").GetObjectId(); NUnit.Framework.Assert.IsTrue(file1Size > 0); NUnit.Framework.Assert.IsTrue(file2Size > 0); NUnit.Framework.Assert.IsTrue(file3Size > 0); // Smudge entries cache = DirCache.Lock(db.GetIndexFile(), db.FileSystem); cache.GetEntry("file1.txt").SetLength(0); cache.GetEntry("file2.txt").SetLength(0); cache.GetEntry("file3.txt").SetLength(0); cache.Write(); NUnit.Framework.Assert.IsTrue(cache.Commit()); // Verify entries smudged cache = DirCache.Read(db.GetIndexFile(), db.FileSystem); NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file1.txt").Length); NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file2.txt").Length); NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file3.txt").Length); long indexTime = db.GetIndexFile().LastModified(); db.GetIndexFile().SetLastModified(indexTime - 5000); Write(file1, "content4"); NUnit.Framework.Assert.IsTrue(file1.SetLastModified(file1.LastModified() + 2500)); NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("edit file").SetOnly("file1.txt" ).Call()); cache = db.ReadDirCache(); NUnit.Framework.Assert.AreEqual(file1Size, cache.GetEntry("file1.txt").Length); NUnit.Framework.Assert.AreEqual(file2Size, cache.GetEntry("file2.txt").Length); NUnit.Framework.Assert.AreEqual(file3Size, cache.GetEntry("file3.txt").Length); NUnit.Framework.Assert.AreEqual(file2Id, cache.GetEntry("file2.txt").GetObjectId( )); NUnit.Framework.Assert.AreEqual(file3Id, cache.GetEntry("file3.txt").GetObjectId( )); }
/// <exception cref="System.IO.IOException"></exception> private void AssumeUnchanged(string path) { DirCache dirc = db.LockDirCache(); DirCacheEntry ent = dirc.GetEntry(path); if (ent != null) { ent.IsAssumeValid = true; } dirc.Write(); if (!dirc.Commit()) { throw new IOException("could not commit"); } }