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 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 CanAddAFileToAMSysGitIndexWhereAFileIsAlreadyWaitingToBeCommitted() { //setup of .git directory var resource = new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"), "CorruptIndex")); var tempRepository = new DirectoryInfo(Path.Combine(trash.FullName, "CorruptIndex" + Path.GetRandomFileName())); CopyDirectory(resource.FullName, tempRepository.FullName); var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, ".git")); Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName); using (var repository = new Core.Repository(repositoryPath)) { GitIndex index = repository.Index; Assert.IsNotNull(index); writeTrashFile(Path.Combine(repository.WorkingDirectory.FullName, "c.txt"), "c"); var tree = repository.MapTree(repository.Head.ObjectId); index.add(repository.WorkingDirectory, new FileInfo(Path.Combine(repository.WorkingDirectory.FullName, "c.txt"))); var diff = new IndexDiff(tree, index); diff.Diff(); index.write(); Assert.AreEqual(2, diff.Added.Count); Assert.IsFalse(diff.Added.Contains("a.txt"), "Should not contain a.txt because it is already committed."); Assert.IsTrue(diff.Added.Contains("b.txt"), "Should contain b.txt since it was added by msysgit, but not committed"); Assert.IsTrue(diff.Added.Contains("c.txt"), "Should contain c.txt since it was added by this test, but not committed"); Assert.AreEqual(0, diff.Changed.Count); Assert.AreEqual(0, diff.Modified.Count); Assert.AreEqual(0, diff.Removed.Count); } }
public void CanAddAFileToAMSysGitIndexWhereAFileIsAlreadyWaitingToBeCommitted() { //setup of .git directory var resource = new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"), "CorruptIndex")); var tempRepository = new DirectoryInfo(Path.Combine(trash.FullName, "CorruptIndex" + Path.GetRandomFileName())); CopyDirectory(resource.FullName, tempRepository.FullName); var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, ".git")); Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName); var repository = new Repository(repositoryPath); GitIndex index = repository.Index; Assert.IsNotNull(index); writeTrashFile(Path.Combine(repository.WorkingDirectory.FullName, "c.txt"), "c"); var tree = new Tree(repository); index.add(repository.WorkingDirectory, new FileInfo(Path.Combine(repository.WorkingDirectory.FullName, "c.txt"))); var diff = new IndexDiff(tree, index); diff.Diff(); index.write(); Assert.AreEqual(3, diff.Added.Count); Assert.IsTrue(diff.Added.Contains("a.txt")); Assert.IsTrue(diff.Added.Contains("b.txt")); Assert.IsTrue(diff.Added.Contains("c.txt")); Assert.AreEqual(0, diff.Changed.Count); Assert.AreEqual(0, diff.Modified.Count); Assert.AreEqual(0, diff.Removed.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 Tree(db); t.AddFile("file2").Id = ObjectId.FromString("0123456789012345678901234567890123456789"); t.AddFile("dir/file3").Id = ObjectId.FromString("0123456789012345678901234567890123456789"); Assert.AreEqual(2, t.MemberCount); var tree2 = (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 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 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 testUnchangedComplex() { 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/b.b/b", "a/b.b/b")); 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 Tree(db); t.AddFile("a.b").Id = ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"); t.AddFile("a.c").Id = ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"); t.AddFile("a/b.b/b").Id = ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd"); t.AddFile("a/b").Id = ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415"); t.AddFile("a/c").Id = ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007"); t.AddFile("a=c").Id = ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"); t.AddFile("a=d").Id = ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"); var tree2 = (Tree) t.findTreeMember("a/b.b"); tree2.Id = new ObjectWriter(db).WriteTree(tree2); var tree3 = (Tree) t.findTreeMember("a"); tree3.Id = new ObjectWriter(db).WriteTree(tree3); 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 Tree(db); t.AddFile("file2"); t.AddFile("dir/file3"); Assert.AreEqual(2, t.MemberCount); t.FindBlobMember("file2").Id = ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"); var tree2 = (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); }