public void testDelete() { var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a@b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); index.write(); index.writeTree(); index.remove(trash, new FileInfo(Path.Combine(trash.FullName, "a@b"))); index.write(); Assert.AreEqual("a.b", index.Members[0].Name); Assert.AreEqual("a/b", index.Members[1].Name); var indexr = new GitIndex(db); indexr.Read(); Assert.AreEqual("a.b", indexr.Members[0].Name); Assert.AreEqual("a/b", indexr.Members[1].Name); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
public void testCreateSimpleSortTestIndex() { var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a@b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); index.write(); Assert.AreEqual("a/b", index.GetEntry("a/b").Name); Assert.AreEqual("a@b", index.GetEntry("a@b").Name); Assert.AreEqual("a.b", index.GetEntry("a.b").Name); Assert.IsNull(index.GetEntry("a*b")); // Repeat test for re-Read index var indexr = new GitIndex(db); indexr.Read(); Assert.AreEqual("a/b", indexr.GetEntry("a/b").Name); Assert.AreEqual("a@b", indexr.GetEntry("a@b").Name); Assert.AreEqual("a.b", indexr.GetEntry("a.b").Name); Assert.IsNull(indexr.GetEntry("a*b")); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
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 Core.Tree(db); t.AddFile("file2").Id = ObjectId.FromString("0123456789012345678901234567890123456789"); t.AddFile("dir/file3").Id = ObjectId.FromString("0123456789012345678901234567890123456789"); Assert.AreEqual(2, t.MemberCount); var tree2 = (Core.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 testCheckout() { // Prepare tree, remote it and checkout var index = new GitIndex(db); FileInfo aslashb = writeTrashFile("a/b", "data:a/b"); FileInfo acolonb = writeTrashFile("a@b", "data:a:b"); FileInfo adotb = writeTrashFile("a.b", "data:a.b"); index.add(trash, aslashb); index.add(trash, acolonb); index.add(trash, adotb); index.write(); index.writeTree(); Delete(aslashb); Delete(acolonb); Delete(adotb); Delete(Directory.GetParent(aslashb.FullName)); var index2 = new GitIndex(db); Assert.AreEqual(0, index2.Members.Count); index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84"))); index2.checkout(trash); Assert.AreEqual("data:a/b", Content(aslashb)); Assert.AreEqual("data:a:b", Content(acolonb)); Assert.AreEqual("data:a.b", Content(adotb)); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
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 Core.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 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 testLeavingTree() { var index = new GitIndex(db); index.add(trash, writeTrashFile("foo/bar", "foo/bar")); index.add(trash, writeTrashFile("foobar", "foobar")); new IndexTreeWalker(index, db.MapTree(index.writeTree()), trash, TestTreeOnlyOneLevelTreeVisitor).Walk(); }
public void testIndexOnlySubDirs() { var index = new GitIndex(db); var mainTree = new Core.Tree(db); index.add(trash, writeTrashFile("foo/bar/baz", "foobar")); index.add(trash, writeTrashFile("asdf", "asdf")); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.AreEqual("asdf", IndexOnlyEntriesVisited[0]); Assert.AreEqual("foo/bar/baz", IndexOnlyEntriesVisited[1]); }
public void testIndexOnlyOneLevel() { var index = new GitIndex(db); var mainTree = new Core.Tree(db); index.add(trash, writeTrashFile("foo", "foo")); index.add(trash, writeTrashFile("bar", "bar")); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.AreEqual(2, IndexOnlyEntriesVisited.Count); Assert.IsTrue(IndexOnlyEntriesVisited[0].Equals("bar")); Assert.IsTrue(IndexOnlyEntriesVisited[1].Equals("foo")); }
public void testBoth() { var index = new GitIndex(db); var mainTree = new Core.Tree(db); index.add(trash, writeTrashFile("a", "a")); mainTree.AddFile("b/b"); index.add(trash, writeTrashFile("c", "c")); mainTree.AddFile("c"); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.IsTrue(IndexOnlyEntriesVisited.Contains("a")); Assert.IsTrue(TreeOnlyEntriesVisited.Contains("b/b")); Assert.IsTrue(BothVisited.Contains("c")); }
public void testDirectoryFileSimple() { _theIndex = new GitIndex(db); _theIndex.add(trash, writeTrashFile("DF", "DF")); Core.Tree head = db.MapTree(_theIndex.writeTree()); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "DF"))); _theIndex = new GitIndex(db); _theIndex.add(trash, writeTrashFile("DF/DF", "DF/DF")); Core.Tree merge = db.MapTree(_theIndex.writeTree()); _theIndex = new GitIndex(db); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "DF"))); _theIndex.add(trash, writeTrashFile("DF", "DF")); _theReadTree = new WorkDirCheckout(db, trash, head, _theIndex, merge); _theReadTree.PrescanTwoTrees(); Assert.IsTrue(_theReadTree.Removed.Contains("DF")); Assert.IsTrue(_theReadTree.Updated.ContainsKey("DF/DF")); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "DF"))); _theIndex = new GitIndex(db); _theIndex.add(trash, writeTrashFile("DF/DF", "DF/DF")); _theReadTree = new WorkDirCheckout(db, trash, merge, _theIndex, head); _theReadTree.PrescanTwoTrees(); Assert.IsTrue(_theReadTree.Removed.Contains("DF/DF")); Assert.IsTrue(_theReadTree.Updated.ContainsKey("DF")); }
/// <summary> /// Unstage overwrites staged files in the index with their current version in HEAD. In case of newly added files they are removed from the index. /// </summary> /// <param name="paths">Relative paths to files you want to unstage.</param> public void Unstage(params string[] paths) { GitIndex.RereadIfNecessary(); foreach (var absolute_or_relative_path in paths) { string path = absolute_or_relative_path; if (Path.IsPathRooted(absolute_or_relative_path)) { path = Core.Util.PathUtil.RelativePath(_repo.WorkingDirectory, absolute_or_relative_path); } if (this[path] == null) { return; } var blob = _repo.Get <Leaf>(path); // <--- we wouldn't want to stage something that is not representing a file if (blob == null) { GitIndex.Remove(path); } else { GitIndex.add(Core.Repository.GitInternalSlash(PathEncoding.GetBytes(path)), blob.RawData); } } GitIndex.write(); }
public void testCheckingOutWithConflicts() { var index = new GitIndex(db); index.add(trash, writeTrashFile("bar", "bar")); index.add(trash, writeTrashFile("foo/bar/baz/qux", "foo/bar")); recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); writeTrashFile("bar/baz/qux/foo", "another nasty one"); writeTrashFile("foo", "troublesome little bugger"); var workDirCheckout1 = new WorkDirCheckout(db, trash, index, index); AssertHelper.Throws <CheckoutConflictException>(workDirCheckout1.checkout); var workDirCheckout2 = new WorkDirCheckout(db, trash, index, index) { FailOnConflict = false }; workDirCheckout2.checkout(); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "bar")).IsFile()); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "foo/bar/baz/qux")).IsFile()); var index2 = new GitIndex(db); recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); index2.add(trash, writeTrashFile("bar/baz/qux/foo", "bar")); writeTrashFile("bar/baz/qux/bar", "evil? I thought it said WEEVIL!"); index2.add(trash, writeTrashFile("foo", "lalala")); workDirCheckout2 = new WorkDirCheckout(db, trash, index2, index) { FailOnConflict = false }; workDirCheckout2.checkout(); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "bar")).IsFile()); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "foo/bar/baz/qux")).IsFile()); Assert.IsNotNull(index2.GetEntry("bar")); Assert.IsNotNull(index2.GetEntry("foo/bar/baz/qux")); Assert.IsNull(index2.GetEntry("bar/baz/qux/foo")); Assert.IsNull(index2.GetEntry("foo")); }
public void testReadTree() { // Prepare tree var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a@b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); index.write(); ObjectId id = index.writeTree(); Console.WriteLine("wrote id " + id); Assert.AreEqual("0036d433dc4f10ec47b61abc3ec5033c78d34f84", id.Name); var index2 = new GitIndex(db); index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84"))); IList <GitIndex.Entry> members = index2.Members; Assert.AreEqual(3, members.Count); Assert.AreEqual("a.b", members[0].Name); Assert.AreEqual("a/b", members[1].Name); Assert.AreEqual("a@b", members[2].Name); Assert.AreEqual(3, members.Count); var indexr = new GitIndex(db); indexr.Read(); IList <GitIndex.Entry> membersr = indexr.Members; Assert.AreEqual(3, membersr.Count); Assert.AreEqual("a.b", membersr[0].Name); Assert.AreEqual("a/b", membersr[1].Name); Assert.AreEqual("a@b", membersr[2].Name); Assert.AreEqual(3, membersr.Count); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
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 testUpdateSimpleSortTestIndex() { var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a@b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); writeTrashFile("a/b", "data:a/b modified"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.write(); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
public void testAdded() { var index = new GitIndex(db); writeTrashFile("file1", "file1"); writeTrashFile("dir/subfile", "dir/subfile"); var tree = new Core.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); }
private GitIndex BuildIndex(Dictionary <string, string> indexEntries) { var index = new GitIndex(db); if (indexEntries != null) { foreach (var pair in indexEntries) { index.add(trash, writeTrashFile(pair.Key, pair.Value)).forceRecheck(); } } return(index); }
public void testCheckingOutWithConflicts() { var index = new GitIndex(db); index.add(trash, writeTrashFile("bar", "bar")); index.add(trash, writeTrashFile("foo/bar/baz/qux", "foo/bar")); recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); writeTrashFile("bar/baz/qux/foo", "another nasty one"); writeTrashFile("foo", "troublesome little bugger"); var workDirCheckout1 = new WorkDirCheckout(db, trash, index, index); AssertHelper.Throws<CheckoutConflictException>(workDirCheckout1.checkout); var workDirCheckout2 = new WorkDirCheckout(db, trash, index, index) { FailOnConflict = false }; workDirCheckout2.checkout(); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "bar")).IsFile()); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "foo/bar/baz/qux")).IsFile()); var index2 = new GitIndex(db); recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); index2.add(trash, writeTrashFile("bar/baz/qux/foo", "bar")); writeTrashFile("bar/baz/qux/bar", "evil? I thought it said WEEVIL!"); index2.add(trash, writeTrashFile("foo", "lalala")); workDirCheckout2 = new WorkDirCheckout(db, trash, index2, index) { FailOnConflict = false }; workDirCheckout2.checkout(); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "bar")).IsFile()); Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "foo/bar/baz/qux")).IsFile()); Assert.IsNotNull(index2.GetEntry("bar")); Assert.IsNotNull(index2.GetEntry("foo/bar/baz/qux")); Assert.IsNull(index2.GetEntry("bar/baz/qux/foo")); Assert.IsNull(index2.GetEntry("foo")); }
public void ShouldSupportNotModifiedExtensionlessFilesWithoutContentChecking() { var index = new GitIndex(db); writeTrashFile("extensionless-file", "contents"); var file = new FileInfo(Path.Combine(trash.FullName, "extensionless-file")); index.add(trash, file); var entry = index.GetEntry("extensionless-file"); Assert.IsFalse(entry.IsModified(trash)); }
public void testFindingConflicts() { var index = new GitIndex(db); index.add(trash, writeTrashFile("bar", "bar")); index.add(trash, writeTrashFile("foo/bar/baz/qux", "foo/bar")); recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); writeTrashFile("bar/baz/qux/foo", "another nasty one"); writeTrashFile("foo", "troublesome little bugger"); var workDirCheckout = new WorkDirCheckout(db, trash, index, index); workDirCheckout.PrescanOneTree(); List <string> conflictingEntries = workDirCheckout.Conflicts; Assert.AreEqual("bar/baz/qux/foo", conflictingEntries[0]); Assert.AreEqual("foo", conflictingEntries[1]); var index2 = new GitIndex(db); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); index2.add(trash, writeTrashFile("bar/baz/qux/foo", "bar")); index2.add(trash, writeTrashFile("foo", "lalala")); workDirCheckout = new WorkDirCheckout(db, trash, index2, index); workDirCheckout.PrescanOneTree(); conflictingEntries = workDirCheckout.Conflicts; List <string> removedEntries = workDirCheckout.Removed; Assert.IsTrue(conflictingEntries.Count == 0); Assert.IsTrue(removedEntries.Contains("bar/baz/qux/foo")); Assert.IsTrue(removedEntries.Contains("foo")); }
public void testWriteTree() { var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a@b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); index.write(); ObjectId id = index.writeTree(); Assert.AreEqual("0036d433dc4f10ec47b61abc3ec5033c78d34f84", id.Name); writeTrashFile("a/b", "data:a/b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
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 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, Constants.DOT_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 testUpdateExistingMsysgitIndex() { var index_path = Path.Combine(trash.FullName + "/.git", "index"); new FileInfo("Resources/index_originating_from_msysgit").CopyTo(index_path); var index = new GitIndex(db); index.Read(); var a = writeTrashFile("a.txt", "Data:a"); index.add(trash, a); index.write(); index.Read(); byte[] content = File.ReadAllBytes(index_path); Assert.AreEqual(352, content.Length); }
public void testReadTree2() { // Prepare a larger tree to test some odd cases in tree writing var index = new GitIndex(db); FileInfo f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a"); FileInfo f2 = writeTrashFile("a/c/c", "data:a/c/c"); FileInfo f3 = writeTrashFile("a/b", "data:a/b"); FileInfo f4 = writeTrashFile("a@b", "data:a:b"); FileInfo f5 = writeTrashFile("a/d", "data:a/d"); FileInfo f6 = writeTrashFile("a.b", "data:a.b"); index.add(trash, f1); index.add(trash, f2); index.add(trash, f3); index.add(trash, f4); index.add(trash, f5); index.add(trash, f6); index.write(); ObjectId id = index.writeTree(); Console.WriteLine("wrote id " + id); Assert.AreEqual("5e0bf0aad57706894c15fdf0681c9bc7343274fc", id.Name); var index2 = new GitIndex(db); index2.ReadTree(db.MapTree(ObjectId.FromString("5e0bf0aad57706894c15fdf0681c9bc7343274fc"))); IList <GitIndex.Entry> members = index2.Members; Assert.AreEqual(6, members.Count); Assert.AreEqual("a.b", members[0].Name); Assert.AreEqual("a/a/a/a", members[1].Name); Assert.AreEqual("a/b", members[2].Name); Assert.AreEqual("a/c/c", members[3].Name); Assert.AreEqual("a/d", members[4].Name); Assert.AreEqual("a@b", members[5].Name); // reread and test var indexr = new GitIndex(db); indexr.Read(); IList <GitIndex.Entry> membersr = indexr.Members; Assert.AreEqual(6, membersr.Count); Assert.AreEqual("a.b", membersr[0].Name); Assert.AreEqual("a/a/a/a", membersr[1].Name); Assert.AreEqual("a/b", membersr[2].Name); Assert.AreEqual("a/c/c", membersr[3].Name); Assert.AreEqual("a/d", membersr[4].Name); Assert.AreEqual("a@b", membersr[5].Name); }
public void ShouldAllowComparingOfAlreadyOpenedFile() { var index = new GitIndex(db); var file = writeTrashFile("extensionless-file", "contents"); index.add(trash, file); var entry = index.GetEntry("extensionless-file"); // [henon] failed on my windows box (originally only observed on mono/unix) when executed in resharper or with nunit without waiting a second! // as the timing is not the point of the test here let's wait a sec anyway. Thread.Sleep(TimeSpan.FromSeconds(1)); // replace contents of file (with same size so it passes the size check) using (var writer = file.CreateText()) writer.Write("stnetnoc"); // opening the file for reading shoudn't block us from checking the contents using (file.OpenRead()) Assert.IsTrue(entry.IsModified(trash, true)); }
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 Core.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 = (Core.Tree)t.findTreeMember("a/b.b"); tree2.Id = new ObjectWriter(db).WriteTree(tree2); var tree3 = (Core.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 ShouldAllowComparingOfAlreadyOpenedFile() { var index = new GitIndex(db); var file = writeTrashFile("extensionless-file", "contents"); index.add(trash, file); var entry = index.GetEntry("extensionless-file"); if (AssertHelper.IsRunningOnMono()) { // File timestamps on Unix based systems are only precise to the second Thread.Sleep(TimeSpan.FromSeconds(1)); } // replace contents of file (with same size so it passes the size check) using (var writer = file.CreateText()) writer.Write("stnetnoc"); // opening the file for reading shoudn't block us from checking the contents using (file.OpenRead()) Assert.IsTrue(entry.IsModified(trash, true)); }
public void testCheckout() { // Prepare tree, remote it and checkout var index = new GitIndex(db); FileInfo aslashb = writeTrashFile("a/b", "data:a/b"); FileInfo acolonb = writeTrashFile("a:b", "data:a:b"); FileInfo adotb = writeTrashFile("a.b", "data:a.b"); index.add(trash, aslashb); index.add(trash, acolonb); index.add(trash, adotb); index.write(); index.writeTree(); Delete(aslashb); Delete(acolonb); Delete(adotb); Delete(Directory.GetParent(aslashb.FullName)); var index2 = new GitIndex(db); Assert.AreEqual(0, index2.Members.Length); index2.ReadTree(db.MapTree(ObjectId.FromString("c696abc3ab8e091c665f49d00eb8919690b3aec3"))); index2.checkout(trash); Assert.AreEqual("data:a/b", Content(aslashb)); Assert.AreEqual("data:a:b", Content(acolonb)); Assert.AreEqual("data:a.b", Content(adotb)); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
public void testReadTree() { // Prepare tree var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a:b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a:b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); index.write(); ObjectId id = index.writeTree(); Console.WriteLine("wrote id " + id); Assert.AreEqual("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.Name); var index2 = new GitIndex(db); index2.ReadTree(db.MapTree(ObjectId.FromString("c696abc3ab8e091c665f49d00eb8919690b3aec3"))); GitIndex.Entry[] members = index2.Members; Assert.AreEqual(3, members.Length); Assert.AreEqual("a.b", members[0].Name); Assert.AreEqual("a/b", members[1].Name); Assert.AreEqual("a:b", members[2].Name); Assert.AreEqual(3, members.Length); var indexr = new GitIndex(db); indexr.Read(); GitIndex.Entry[] membersr = indexr.Members; Assert.AreEqual(3, membersr.Length); Assert.AreEqual("a.b", membersr[0].Name); Assert.AreEqual("a/b", membersr[1].Name); Assert.AreEqual("a:b", membersr[2].Name); Assert.AreEqual(3, membersr.Length); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
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 testReadTree() { // Prepare tree var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a@b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a@b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); index.write(); ObjectId id = index.writeTree(); Console.WriteLine("wrote id " + id); Assert.AreEqual("0036d433dc4f10ec47b61abc3ec5033c78d34f84", id.Name); var index2 = new GitIndex(db); index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84"))); IList<GitIndex.Entry> members = index2.Members; Assert.AreEqual(3, members.Count); Assert.AreEqual("a.b", members[0].Name); Assert.AreEqual("a/b", members[1].Name); Assert.AreEqual("a@b", members[2].Name); Assert.AreEqual(3, members.Count); var indexr = new GitIndex(db); indexr.Read(); IList<GitIndex.Entry> membersr = indexr.Members; Assert.AreEqual(3, membersr.Count); Assert.AreEqual("a.b", membersr[0].Name); Assert.AreEqual("a/b", membersr[1].Name); Assert.AreEqual("a@b", membersr[2].Name); Assert.AreEqual(3, membersr.Count); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
public void testIndexOnlySubDirs() { var index = new GitIndex(db); var mainTree = new Tree(db); index.add(trash, writeTrashFile("foo/bar/baz", "foobar")); index.add(trash, writeTrashFile("asdf", "asdf")); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.AreEqual("asdf", IndexOnlyEntriesVisited[0]); Assert.AreEqual("foo/bar/baz", IndexOnlyEntriesVisited[1]); }
public void testIndexOnlyOneLevel() { var index = new GitIndex(db); var mainTree = new Tree(db); index.add(trash, writeTrashFile("foo", "foo")); index.add(trash, writeTrashFile("bar", "bar")); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.AreEqual(2, IndexOnlyEntriesVisited.Count); Assert.IsTrue(IndexOnlyEntriesVisited[0].Equals("bar")); Assert.IsTrue(IndexOnlyEntriesVisited[1].Equals("foo")); }
public void testBoth() { var index = new GitIndex(db); var mainTree = new Tree(db); index.add(trash, writeTrashFile("a", "a")); mainTree.AddFile("b/b"); index.add(trash, writeTrashFile("c", "c")); mainTree.AddFile("c"); new IndexTreeWalker(index, mainTree, trash, TestIndexTreeVisitor).Walk(); Assert.IsTrue(IndexOnlyEntriesVisited.Contains("a")); Assert.IsTrue(TreeOnlyEntriesVisited.Contains("b/b")); Assert.IsTrue(BothVisited.Contains("c")); }
public void testWriteTree() { var index = new GitIndex(db); writeTrashFile("a/b", "data:a/b"); writeTrashFile("a:b", "data:a:b"); writeTrashFile("a.b", "data:a.b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a:b"))); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a.b"))); index.write(); ObjectId id = index.writeTree(); Assert.AreEqual("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.Name); writeTrashFile("a/b", "data:a/b"); index.add(trash, new FileInfo(Path.Combine(trash.FullName, "a/b"))); if (CanRunGitStatus) { Assert.AreEqual(0, System(trash, "git status")); } }
public void testReadTree2() { // Prepare a larger tree to test some odd cases in tree writing var index = new GitIndex(db); FileInfo f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a"); FileInfo f2 = writeTrashFile("a/c/c", "data:a/c/c"); FileInfo f3 = writeTrashFile("a/b", "data:a/b"); FileInfo f4 = writeTrashFile("a:b", "data:a:b"); FileInfo f5 = writeTrashFile("a/d", "data:a/d"); FileInfo f6 = writeTrashFile("a.b", "data:a.b"); index.add(trash, f1); index.add(trash, f2); index.add(trash, f3); index.add(trash, f4); index.add(trash, f5); index.add(trash, f6); index.write(); ObjectId id = index.writeTree(); Console.WriteLine("wrote id " + id); Assert.AreEqual("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.Name); var index2 = new GitIndex(db); index2.ReadTree(db.MapTree(ObjectId.FromString("ba78e065e2c261d4f7b8f42107588051e87e18e9"))); GitIndex.Entry[] members = index2.Members; Assert.AreEqual(6, members.Length); Assert.AreEqual("a.b", members[0].Name); Assert.AreEqual("a/a/a/a", members[1].Name); Assert.AreEqual("a/b", members[2].Name); Assert.AreEqual("a/c/c", members[3].Name); Assert.AreEqual("a/d", members[4].Name); Assert.AreEqual("a:b", members[5].Name); // reread and test var indexr = new GitIndex(db); indexr.Read(); GitIndex.Entry[] membersr = indexr.Members; Assert.AreEqual(6, membersr.Length); Assert.AreEqual("a.b", membersr[0].Name); Assert.AreEqual("a/a/a/a", membersr[1].Name); Assert.AreEqual("a/b", membersr[2].Name); Assert.AreEqual("a/c/c", membersr[3].Name); Assert.AreEqual("a/d", membersr[4].Name); Assert.AreEqual("a:b", membersr[5].Name); }
private GitIndex BuildIndex(Dictionary<string, string> indexEntries) { var index = new GitIndex(db); if (indexEntries != null) { foreach (var pair in indexEntries) { index.add(trash, writeTrashFile(pair.Key, pair.Value)).forceRecheck(); } } return index; }
public void testReadTree2() { // Prepare a larger tree to test some odd cases in tree writing var index = new GitIndex(db); FileInfo f1 = writeTrashFile("a/a/a/a", "data:a/a/a/a"); FileInfo f2 = writeTrashFile("a/c/c", "data:a/c/c"); FileInfo f3 = writeTrashFile("a/b", "data:a/b"); FileInfo f4 = writeTrashFile("a@b", "data:a:b"); FileInfo f5 = writeTrashFile("a/d", "data:a/d"); FileInfo f6 = writeTrashFile("a.b", "data:a.b"); index.add(trash, f1); index.add(trash, f2); index.add(trash, f3); index.add(trash, f4); index.add(trash, f5); index.add(trash, f6); index.write(); ObjectId id = index.writeTree(); Console.WriteLine("wrote id " + id); Assert.AreEqual("5e0bf0aad57706894c15fdf0681c9bc7343274fc", id.Name); var index2 = new GitIndex(db); index2.ReadTree(db.MapTree(ObjectId.FromString("5e0bf0aad57706894c15fdf0681c9bc7343274fc"))); IList<GitIndex.Entry> members = index2.Members; Assert.AreEqual(6, members.Count); Assert.AreEqual("a.b", members[0].Name); Assert.AreEqual("a/a/a/a", members[1].Name); Assert.AreEqual("a/b", members[2].Name); Assert.AreEqual("a/c/c", members[3].Name); Assert.AreEqual("a/d", members[4].Name); Assert.AreEqual("a@b", members[5].Name); // reread and test var indexr = new GitIndex(db); indexr.Read(); IList<GitIndex.Entry> membersr = indexr.Members; Assert.AreEqual(6, membersr.Count); Assert.AreEqual("a.b", membersr[0].Name); Assert.AreEqual("a/a/a/a", membersr[1].Name); Assert.AreEqual("a/b", membersr[2].Name); Assert.AreEqual("a/c/c", membersr[3].Name); Assert.AreEqual("a/d", membersr[4].Name); Assert.AreEqual("a@b", membersr[5].Name); }
public void testFindingConflicts() { var index = new GitIndex(db); index.add(trash, writeTrashFile("bar", "bar")); index.add(trash, writeTrashFile("foo/bar/baz/qux", "foo/bar")); recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); writeTrashFile("bar/baz/qux/foo", "another nasty one"); writeTrashFile("foo", "troublesome little bugger"); var workDirCheckout = new WorkDirCheckout(db, trash, index, index); workDirCheckout.PrescanOneTree(); List<string> conflictingEntries = workDirCheckout.Conflicts; Assert.AreEqual("bar/baz/qux/foo", conflictingEntries[0]); Assert.AreEqual("foo", conflictingEntries[1]); var index2 = new GitIndex(db); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "bar"))); recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo"))); index2.add(trash, writeTrashFile("bar/baz/qux/foo", "bar")); index2.add(trash, writeTrashFile("foo", "lalala")); workDirCheckout = new WorkDirCheckout(db, trash, index2, index); workDirCheckout.PrescanOneTree(); conflictingEntries = workDirCheckout.Conflicts; List<string> removedEntries = workDirCheckout.Removed; Assert.IsTrue(conflictingEntries.Count == 0); Assert.IsTrue(removedEntries.Contains("bar/baz/qux/foo")); Assert.IsTrue(removedEntries.Contains("foo")); }
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); }