Beispiel #1
0
        public virtual void TestConflictingFromMultipleCreations()
        {
            Git git = new Git(db);

            WriteTrashFile("a", "1\na\n3\n");
            git.Add().AddFilepattern("a").Call();
            RevCommit initialCommit = git.Commit().SetMessage("initial").Call();

            CreateBranch(initialCommit, "refs/heads/side");
            CheckoutBranch("refs/heads/side");
            WriteTrashFile("b", "1\nb(side)\n3\n");
            git.Add().AddFilepattern("b").Call();
            RevCommit secondCommit = git.Commit().SetMessage("side").Call();

            CheckoutBranch("refs/heads/master");
            WriteTrashFile("b", "1\nb(main)\n3\n");
            git.Add().AddFilepattern("b").Call();
            git.Commit().SetMessage("main").Call();
            MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
                                                                                         .RESOLVE).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, Constants.HEAD, iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual("[]", new TreeSet <string>(diff.GetChanged()).ToString
                                                ());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetAdded().ToString());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetRemoved().ToString());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetMissing().ToString());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetModified().ToString());
            NUnit.Framework.Assert.AreEqual("[b]", diff.GetConflicting().ToString());
        }
        public virtual void TestModified()
        {
            WriteTrashFile("file2", "file2");
            WriteTrashFile("dir/file3", "dir/file3");
            Git git = new Git(db);

            git.Add().AddFilepattern("file2").AddFilepattern("dir/file3").Call();
            WriteTrashFile("dir/file3", "changed");
            Tree tree = new Tree(db);

            tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                            ));
            tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                                ));
            NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
            Tree tree2 = (Tree)tree.FindTreeMember("dir");

            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders()
                                            );
        }
Beispiel #3
0
        public virtual void TestUnchangedSimple()
        {
            GitIndex 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"));
            index.Write();
            Tree tree = new Tree(db);

            // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
            tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
                                                          ));
            tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
                                                          ));
            tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
                                                          ));
            tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
                                                          ));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
        }
        public virtual void TestAdded()
        {
            WriteTrashFile("file1", "file1");
            WriteTrashFile("dir/subfile", "dir/subfile");
            Tree tree = new Tree(db);

            tree.SetId(InsertTree(tree));
            DirCache       index  = db.LockDirCache();
            DirCacheEditor editor = index.Editor();

            editor.Add(Add(db, trash, "file1"));
            editor.Add(Add(db, trash, "dir/subfile"));
            editor.Commit();
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.CollectionAssert.AreEquivalent(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders()
                                                           );
        }
Beispiel #5
0
        public virtual void TestAssumeUnchanged()
        {
            Git    git  = new Git(db);
            string path = "file";

            WriteTrashFile(path, "content");
            git.Add().AddFilepattern(path).Call();
            string path2 = "file2";

            WriteTrashFile(path2, "content");
            git.Add().AddFilepattern(path2).Call();
            git.Commit().SetMessage("commit").Call();
            AssumeUnchanged(path2);
            WriteTrashFile(path, "more content");
            WriteTrashFile(path2, "more content");
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, Constants.HEAD, iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count);
            NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("file"));
            git.Add().AddFilepattern(".").Call();
            iterator = new FileTreeIterator(db);
            diff     = new IndexDiff(db, Constants.HEAD, iterator);
            diff.Diff();
            NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(1, diff.GetChanged().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file"));
        }
Beispiel #6
0
        public virtual void TestRemoved()
        {
            WriteTrashFile("file2", "file2");
            WriteTrashFile("dir/file3", "dir/file3");
            Tree tree = new Tree(db);

            tree.AddFile("file2");
            tree.AddFile("dir/file3");
            NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
            tree.FindBlobMember("file2").SetId(ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"
                                                                   ));
            Tree tree2 = (Tree)tree.FindTreeMember("dir");

            tree2.FindBlobMember("file3").SetId(ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"
                                                                    ));
            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetRemoved().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
        }
Beispiel #7
0
        public void CommitDiffs()
        {
            Assert.IsNull(nGit.head());
            nGit.file_Create("testFile.txt", "some Text");
            "head 1 :{0}".info(nGit.head().info());
            nGit.add_and_Commit_using_Status();
            "head 2 :{0}".info(nGit.head().info());
            nGit.file_Write("testFile.txt", "some Text changed");
            nGit.add_and_Commit_using_Status();
            var head3 = nGit.head();
            "head 3 :{0}".info(head3.info());

            var workingTreeIt = new FileTreeIterator(nGit.Repository);

            var indexDiff = new IndexDiff(nGit.Repository, Constants.HEAD, workingTreeIt);
            indexDiff.Diff();
            var result = new Status(indexDiff);
            "RESULT: {0}".info(result);

            /*OutputStream outputStream = "Sharpen.dll".assembly().type("ByteArrayOutputStream").ctor(new object[0]).cast<OutputStream>();

            var diffFormater = new DiffFormatter(outputStream);
            diffFormater.SetRepository(nGit.Repository);
            //diffFormater.Format(refLog.GetNewId(), refLog.GetOldId());
            diffFormater.Format(refLog.GetOldId(), refLog.GetNewId());*/
        }
Beispiel #8
0
        public virtual void TestModified()
        {
            GitIndex index = new GitIndex(db);

            index.Add(trash, WriteTrashFile("file2", "file2"));
            index.Add(trash, WriteTrashFile("dir/file3", "dir/file3"));
            index.Write();
            WriteTrashFile("dir/file3", "changed");
            Tree tree = new Tree(db);

            tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                            ));
            tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
                                                                ));
            NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
            Tree tree2 = (Tree)tree.FindTreeMember("dir");

            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
            NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
        }
        public virtual void TestUnchangedComplex()
        {
            Git git = new Git(db);

            WriteTrashFile("a.b", "a.b");
            WriteTrashFile("a.c", "a.c");
            WriteTrashFile("a/b.b/b", "a/b.b/b");
            WriteTrashFile("a/b", "a/b");
            WriteTrashFile("a/c", "a/c");
            WriteTrashFile("a=c", "a=c");
            WriteTrashFile("a=d", "a=d");
            git.Add().AddFilepattern("a.b").AddFilepattern("a.c").AddFilepattern("a/b.b/b").AddFilepattern
                ("a/b").AddFilepattern("a/c").AddFilepattern("a=c").AddFilepattern("a=d").Call();
            Tree tree = new Tree(db);

            // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
            tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
                                                          ));
            tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
                                                          ));
            tree.AddFile("a/b.b/b").SetId(ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd"
                                                              ));
            tree.AddFile("a/b").SetId(ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415"
                                                          ));
            tree.AddFile("a/c").SetId(ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007"
                                                          ));
            tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
                                                          ));
            tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
                                                          ));
            Tree tree3 = (Tree)tree.FindTreeMember("a/b.b");

            tree3.SetId(InsertTree(tree3));
            Tree tree2 = (Tree)tree.FindTreeMember("a");

            tree2.SetId(InsertTree(tree2));
            tree.SetId(InsertTree(tree));
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders()
                                            );
        }
		public override NGit.Api.Status Call ()
		{
			if (iter == null)
				iter = new FileTreeIterator(repo);
			
			IndexDiff diff = new IndexDiff(repo, Constants.HEAD, iter);
			if (Files != null) {
				var filters = Files.Where (f => f != ".").ToArray ();
				if (filters.Length > 0)
					diff.SetFilter (PathFilterGroup.CreateFromStrings (filters));
			}
			
			diff.Diff ();
			return new NGit.Api.Status(diff);
		}
Beispiel #11
0
        public virtual void TestRemovedUntracked()
        {
            Git    git  = new Git(db);
            string path = "file";

            WriteTrashFile(path, "content");
            git.Add().AddFilepattern(path).Call();
            git.Commit().SetMessage("commit").Call();
            RemoveFromIndex(path);
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, Constants.HEAD, iterator);

            diff.Diff();
            NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains(path));
            NUnit.Framework.Assert.IsTrue(diff.GetUntracked().Contains(path));
        }
Beispiel #12
0
 public virtual void TestAdded()
 {
     GitIndex index = new GitIndex(db);
     WriteTrashFile("file1", "file1");
     WriteTrashFile("dir/subfile", "dir/subfile");
     Tree tree = new Tree(db);
     tree.SetId(InsertTree(tree));
     index.Add(trash, new FilePath(trash, "file1"));
     index.Add(trash, new FilePath(trash, "dir/subfile"));
     index.Write();
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
 }
        public virtual void TestConflicting()
        {
            Git git = new Git(db);

            WriteTrashFile("a", "1\na\n3\n");
            WriteTrashFile("b", "1\nb\n3\n");
            git.Add().AddFilepattern("a").AddFilepattern("b").Call();
            RevCommit initialCommit = git.Commit().SetMessage("initial").Call();

            // create side branch with two modifications
            CreateBranch(initialCommit, "refs/heads/side");
            CheckoutBranch("refs/heads/side");
            WriteTrashFile("a", "1\na(side)\n3\n");
            WriteTrashFile("b", "1\nb\n3\n(side)");
            git.Add().AddFilepattern("a").AddFilepattern("b").Call();
            RevCommit secondCommit = git.Commit().SetMessage("side").Call();

            // update a on master to generate conflict
            CheckoutBranch("refs/heads/master");
            WriteTrashFile("a", "1\na(main)\n3\n");
            git.Add().AddFilepattern("a").Call();
            git.Commit().SetMessage("main").Call();
            // merge side with master
            MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
                                                                                         .RESOLVE).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, Constants.HEAD, iterator);

            diff.Diff();
            NUnit.Framework.CollectionAssert.AreEqual("[b]", new TreeSet <string>(diff.GetChanged()).ToString
                                                          ());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetAdded());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetRemoved());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetMissing());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetModified());
            NUnit.Framework.Assert.AreEqual("a", diff.GetConflicting().First());
            NUnit.Framework.Assert.AreEqual(1, diff.GetConflicting().Count());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetUntrackedFolders());
        }
Beispiel #14
0
 public virtual void TestAdded()
 {
     WriteTrashFile("file1", "file1");
     WriteTrashFile("dir/subfile", "dir/subfile");
     Tree tree = new Tree(db);
     tree.SetId(InsertTree(tree));
     DirCache index = db.LockDirCache();
     DirCacheEditor editor = index.Editor();
     editor.Add(Add(db, trash, "file1"));
     editor.Add(Add(db, trash, "dir/subfile"));
     editor.Commit();
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
     NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Beispiel #15
0
        public virtual void TestAdded()
        {
            GitIndex index = new GitIndex(db);

            WriteTrashFile("file1", "file1");
            WriteTrashFile("dir/subfile", "dir/subfile");
            Tree tree = new Tree(db);

            tree.SetId(InsertTree(tree));
            index.Add(trash, new FilePath(trash, "file1"));
            index.Add(trash, new FilePath(trash, "dir/subfile"));
            index.Write();
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, tree.GetId(), iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(2, diff.GetAdded().Count);
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("file1"));
            NUnit.Framework.Assert.IsTrue(diff.GetAdded().Contains("dir/subfile"));
            NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
            NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
        }
        public virtual void TestUntrackedFolders()
        {
            Git       git  = new Git(db);
            IndexDiff diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));

            diff.Diff();
            NUnit.Framework.Assert.AreEqual(Collections <string> .EMPTY_SET, diff.GetUntrackedFolders()
                                            );
            WriteTrashFile("readme", string.Empty);
            WriteTrashFile("src/com/A.java", string.Empty);
            WriteTrashFile("src/com/B.java", string.Empty);
            WriteTrashFile("src/org/A.java", string.Empty);
            WriteTrashFile("src/org/B.java", string.Empty);
            WriteTrashFile("target/com/A.java", string.Empty);
            WriteTrashFile("target/com/B.java", string.Empty);
            WriteTrashFile("target/org/A.java", string.Empty);
            WriteTrashFile("target/org/B.java", string.Empty);
            git.Add().AddFilepattern("src").AddFilepattern("readme").Call();
            git.Commit().SetMessage("initial").Call();
            diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
            diff.Diff();
            NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet <string>(Arrays.AsList("target")), diff
                                                           .GetUntrackedFolders());
            WriteTrashFile("src/tst/A.java", string.Empty);
            WriteTrashFile("src/tst/B.java", string.Empty);
            diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
            diff.Diff();
            NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet <string>(Arrays.AsList("target", "src/tst"
                                                                                              )), diff.GetUntrackedFolders());
            git.Rm().AddFilepattern("src/com/B.java").AddFilepattern("src/org").Call();
            git.Commit().SetMessage("second").Call();
            WriteTrashFile("src/org/C.java", string.Empty);
            diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
            diff.Diff();
            NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet <string>(Arrays.AsList("src/org", "src/tst"
                                                                                              , "target")), diff.GetUntrackedFolders());
        }
Beispiel #17
0
 public virtual void TestAssumeUnchanged()
 {
     Git git = new Git(db);
     string path = "file";
     WriteTrashFile(path, "content");
     git.Add().AddFilepattern(path).Call();
     string path2 = "file2";
     WriteTrashFile(path2, "content");
     git.Add().AddFilepattern(path2).Call();
     git.Commit().SetMessage("commit").Call();
     AssumeUnchanged(path2);
     WriteTrashFile(path, "more content");
     WriteTrashFile(path2, "more content");
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count);
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("file"));
     git.Add().AddFilepattern(".").Call();
     iterator = new FileTreeIterator(db);
     diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(1, diff.GetAssumeUnchanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(1, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetAssumeUnchanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file"));
     NUnit.Framework.CollectionAssert.AreEquivalent(Sharpen.Collections<string>.EMPTY_SET, diff.GetUntrackedFolders
         ());
 }
Beispiel #18
0
 public virtual void TestUntrackedFolders()
 {
     Git git = new Git(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
     diff.Diff();
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
     WriteTrashFile("readme", string.Empty);
     WriteTrashFile("src/com/A.java", string.Empty);
     WriteTrashFile("src/com/B.java", string.Empty);
     WriteTrashFile("src/org/A.java", string.Empty);
     WriteTrashFile("src/org/B.java", string.Empty);
     WriteTrashFile("target/com/A.java", string.Empty);
     WriteTrashFile("target/com/B.java", string.Empty);
     WriteTrashFile("target/org/A.java", string.Empty);
     WriteTrashFile("target/org/B.java", string.Empty);
     git.Add().AddFilepattern("src").AddFilepattern("readme").Call();
     git.Commit().SetMessage("initial").Call();
     diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
     diff.Diff();
     NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet<string>(Arrays.AsList("target")), diff
         .GetUntrackedFolders());
     WriteTrashFile("src/tst/A.java", string.Empty);
     WriteTrashFile("src/tst/B.java", string.Empty);
     diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
     diff.Diff();
     NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet<string>(Arrays.AsList("target", "src/tst"
         )), diff.GetUntrackedFolders());
     git.Rm().AddFilepattern("src/com/B.java").AddFilepattern("src/org").Call();
     git.Commit().SetMessage("second").Call();
     WriteTrashFile("src/org/C.java", string.Empty);
     diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
     diff.Diff();
     NUnit.Framework.CollectionAssert.AreEquivalent(new HashSet<string>(Arrays.AsList("src/org", "src/tst"
         , "target")), diff.GetUntrackedFolders());
 }
Beispiel #19
0
 public virtual void TestUnchangedSimple()
 {
     WriteTrashFile("a.b", "a.b");
     WriteTrashFile("a.c", "a.c");
     WriteTrashFile("a=c", "a=c");
     WriteTrashFile("a=d", "a=d");
     Git git = new Git(db);
     git.Add().AddFilepattern("a.b").Call();
     git.Add().AddFilepattern("a.c").Call();
     git.Add().AddFilepattern("a=c").Call();
     git.Add().AddFilepattern("a=d").Call();
     Tree tree = new Tree(db);
     // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
     tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
         ));
     tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
         ));
     tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
         ));
     tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
         ));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Beispiel #20
0
 public virtual void TestUnchangedComplex()
 {
     Git git = new Git(db);
     WriteTrashFile("a.b", "a.b");
     WriteTrashFile("a.c", "a.c");
     WriteTrashFile("a/b.b/b", "a/b.b/b");
     WriteTrashFile("a/b", "a/b");
     WriteTrashFile("a/c", "a/c");
     WriteTrashFile("a=c", "a=c");
     WriteTrashFile("a=d", "a=d");
     git.Add().AddFilepattern("a.b").AddFilepattern("a.c").AddFilepattern("a/b.b/b").AddFilepattern
         ("a/b").AddFilepattern("a/c").AddFilepattern("a=c").AddFilepattern("a=d").Call();
     Tree tree = new Tree(db);
     // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
     tree.AddFile("a.b").SetId(ObjectId.FromString("f6f28df96c2b40c951164286e08be7c38ec74851"
         ));
     tree.AddFile("a.c").SetId(ObjectId.FromString("6bc0e647512d2a0bef4f26111e484dc87df7f5ca"
         ));
     tree.AddFile("a/b.b/b").SetId(ObjectId.FromString("8d840bd4e2f3a48ff417c8e927d94996849933fd"
         ));
     tree.AddFile("a/b").SetId(ObjectId.FromString("db89c972fc57862eae378f45b74aca228037d415"
         ));
     tree.AddFile("a/c").SetId(ObjectId.FromString("52ad142a008aeb39694bafff8e8f1be75ed7f007"
         ));
     tree.AddFile("a=c").SetId(ObjectId.FromString("06022365ddbd7fb126761319633bf73517770714"
         ));
     tree.AddFile("a=d").SetId(ObjectId.FromString("fa6414df3da87840700e9eeb7fc261dd77ccd5c2"
         ));
     Tree tree3 = (Tree)tree.FindTreeMember("a/b.b");
     tree3.SetId(InsertTree(tree3));
     Tree tree2 = (Tree)tree.FindTreeMember("a");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Beispiel #21
0
 public virtual void TestRemovedUntracked()
 {
     Git git = new Git(db);
     string path = "file";
     WriteTrashFile(path, "content");
     git.Add().AddFilepattern(path).Call();
     git.Commit().SetMessage("commit").Call();
     RemoveFromIndex(path);
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains(path));
     NUnit.Framework.Assert.IsTrue(diff.GetUntracked().Contains(path));
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Beispiel #22
0
 public virtual void TestModified()
 {
     GitIndex index = new GitIndex(db);
     index.Add(trash, WriteTrashFile("file2", "file2"));
     index.Add(trash, WriteTrashFile("dir/file3", "dir/file3"));
     index.Write();
     WriteTrashFile("dir/file3", "changed");
     Tree tree = new Tree(db);
     tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
 }
Beispiel #23
0
 public virtual void TestModified()
 {
     WriteTrashFile("file2", "file2");
     WriteTrashFile("dir/file3", "dir/file3");
     Git git = new Git(db);
     git.Add().AddFilepattern("file2").AddFilepattern("dir/file3").Call();
     WriteTrashFile("dir/file3", "changed");
     Tree tree = new Tree(db);
     tree.AddFile("file2").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     tree.AddFile("dir/file3").SetId(ObjectId.FromString("0123456789012345678901234567890123456789"
         ));
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetChanged().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetChanged().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(1, diff.GetModified().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetModified().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetRemoved().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetMissing().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }
Beispiel #24
0
 public virtual void TestConflictingFromMultipleCreations()
 {
     Git git = new Git(db);
     WriteTrashFile("a", "1\na\n3\n");
     git.Add().AddFilepattern("a").Call();
     RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
     CreateBranch(initialCommit, "refs/heads/side");
     CheckoutBranch("refs/heads/side");
     WriteTrashFile("b", "1\nb(side)\n3\n");
     git.Add().AddFilepattern("b").Call();
     RevCommit secondCommit = git.Commit().SetMessage("side").Call();
     CheckoutBranch("refs/heads/master");
     WriteTrashFile("b", "1\nb(main)\n3\n");
     git.Add().AddFilepattern("b").Call();
     git.Commit().SetMessage("main").Call();
     MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
         .RESOLVE).Call();
     NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual("[]", new TreeSet<string>(diff.GetChanged()).ToString
         ());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetAdded());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetRemoved());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetMissing());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetModified());
     NUnit.Framework.Assert.AreEqual(1, diff.GetConflicting().Count());
     NUnit.Framework.Assert.AreEqual("b", diff.GetConflicting().First());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetUntrackedFolders()
         );
 }
Beispiel #25
0
		public virtual void TestConflictingDeletedAndModified()
		{
			Git git = new Git(db);
			WriteTrashFile("a", "1\na\n3\n");
			WriteTrashFile("b", "1\nb\n3\n");
			git.Add().AddFilepattern("a").AddFilepattern("b").Call();
			RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
			// create side branch and delete "a"
			CreateBranch(initialCommit, "refs/heads/side");
			CheckoutBranch("refs/heads/side");
			git.Rm().AddFilepattern("a").Call();
			RevCommit secondCommit = git.Commit().SetMessage("side").Call();
			// update a on master to generate conflict
			CheckoutBranch("refs/heads/master");
			WriteTrashFile("a", "1\na(main)\n3\n");
			git.Add().AddFilepattern("a").Call();
			git.Commit().SetMessage("main").Call();
			// merge side with master
			MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
				.RESOLVE).Call();
			NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
			FileTreeIterator iterator = new FileTreeIterator(db);
			IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
			diff.Diff();
			NUnit.Framework.Assert.AreEqual("[]", new TreeSet<string>(diff.GetChanged()).ToString
				());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetAdded().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetRemoved().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetMissing().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetModified().ToString());
			NUnit.Framework.Assert.AreEqual("[a]", diff.GetConflicting().ToString());
		}
Beispiel #26
0
		public override NGit.Api.Status Call ()
		{
			if (iter == null)
				iter = new FileTreeIterator(repo);
			
			IndexDiff diff = new IndexDiff(repo, Constants.HEAD, iter);
			if (Files != null) {
				var filters = Files.Select (PathFilter.Create).ToArray ();
				if (filters.Length > 1)
					diff.SetFilter (OrTreeFilter.Create (filters));
				else
					diff.SetFilter (filters [0]);
			}
			
			diff.Diff ();
			return new NGit.Api.Status(diff);
		}
Beispiel #27
0
        protected void RaiseNotifyFromDiff(Repository repository)
        {
            if (repository == null)
                throw new ArgumentNullException("repository");
            var workingTreeIt = new FileTreeIterator(repository);
            var diff = new IndexDiff(repository, Constants.HEAD, workingTreeIt);

            diff.Diff();

            RaiseNotifyFromDiff(repository, diff.GetAdded(), GitNotifyAction.UpdateAdd);
            RaiseNotifyFromDiff(repository, diff.GetAssumeUnchanged(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetChanged(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetConflicting(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetMissing(), GitNotifyAction.UpdateDeleted);
            RaiseNotifyFromDiff(repository, diff.GetModified(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetRemoved(), GitNotifyAction.UpdateDeleted);
            RaiseNotifyFromDiff(repository, diff.GetUntracked(), GitNotifyAction.UpdateUpdate);
        }
        public GitFileStatus GetFileStatusNoCache(string fileName)
        {
            //Debug.WriteLine(string.Format("===+ GetFileStatusNoCache {0}", fileName));

            var fileNameRel = GetRelativeFileNameForGit(fileName);

            IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, new FileTreeIterator(repository));
            indexDiff.SetFilter(PathFilterGroup.CreateFromStrings(fileNameRel));
            indexDiff.Diff();

            if (indexDiff.GetModified().Count > 0)
                return GitFileStatus.Modified;

            if (indexDiff.GetConflicting().Count > 0)
                return GitFileStatus.Conflict;

            if (indexDiff.GetUntracked().Count > 0 || indexDiff.GetUntrackedFolders().Count > 0)
            {
                if (File.Exists(fileName))
                    return GitFileStatus.New;

                return GitFileStatus.NotControlled;
            }

            if (indexDiff.GetAdded().Count > 0)
                return GitFileStatus.Added;

            if (!File.Exists(fileName))
            {
                if (indexDiff.GetMissing().Count > 0)
                    return GitFileStatus.Removed;

                return GitFileStatus.Deleted;
            }

            if (indexDiff.GetChanged().Count > 0)
                return GitFileStatus.Staged;

            if (indexDiff.GetIgnoredNotInIndex().Count > 0)
                return GitFileStatus.Ignored;

            return GitFileStatus.Tracked;
        }
Beispiel #29
0
 public virtual void TestRemoved()
 {
     WriteTrashFile("file2", "file2");
     WriteTrashFile("dir/file3", "dir/file3");
     Tree tree = new Tree(db);
     tree.AddFile("file2");
     tree.AddFile("dir/file3");
     NUnit.Framework.Assert.AreEqual(2, tree.MemberCount());
     tree.FindBlobMember("file2").SetId(ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad"
         ));
     Tree tree2 = (Tree)tree.FindTreeMember("dir");
     tree2.FindBlobMember("file3").SetId(ObjectId.FromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"
         ));
     tree2.SetId(InsertTree(tree2));
     tree.SetId(InsertTree(tree));
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, tree.GetId(), iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual(2, diff.GetRemoved().Count);
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("file2"));
     NUnit.Framework.Assert.IsTrue(diff.GetRemoved().Contains("dir/file3"));
     NUnit.Framework.Assert.AreEqual(0, diff.GetChanged().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetModified().Count);
     NUnit.Framework.Assert.AreEqual(0, diff.GetAdded().Count);
     NUnit.Framework.CollectionAssert.AreEquivalent(Collections<string>.EMPTY_SET, diff.GetUntrackedFolders()
         );
 }