Example #1
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());*/
        }
Example #2
0
        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);
        }
Example #3
0
        public void testRemoved()
        {
            var index = new GitIndex(db);

            writeTrashFile("file2", "file2");
            writeTrashFile("dir/file3", "dir/file3");

            var t = new Core.Tree(db);

            t.AddFile("file2");
            t.AddFile("dir/file3");
            Assert.AreEqual(2, t.MemberCount);
            t.FindBlobMember("file2").Id = ObjectId.FromString("30d67d4672d5c05833b7192cc77a79eaafb5c7ad");
            var tree2 = (Core.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);
        }
Example #4
0
        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);
        }
Example #5
0
 /// <param name="diff"></param>
 public Status(IndexDiff diff) : base()
 {
     this.diff = diff;
     clean     = diff.GetAdded().IsEmpty() && diff.GetChanged().IsEmpty() && diff.GetRemoved
                     ().IsEmpty() && diff.GetMissing().IsEmpty() && diff.GetModified().IsEmpty() && diff
                 .GetUntracked().IsEmpty() && diff.GetConflicting().IsEmpty();
 }
        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);
        }
Example #7
0
        // TODO Auto-generated constructor stub
        /// <summary>
        /// Executes the
        /// <code>Status</code>
        /// command with all the options and parameters
        /// collected by the setter methods of this class. Each instance of this
        /// class should only be used for one invocation of the command. Don't call
        /// this method twice on an instance.
        /// </summary>
        /// <returns>
        /// a
        /// <see cref="Status">Status</see>
        /// object telling about each path where working
        /// tree, index or HEAD differ from each other.
        /// </returns>
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Errors.NoWorkTreeException"></exception>
        public override Status Call()
        {
            if (workingTreeIt == null)
            {
                workingTreeIt = new FileTreeIterator(repo);
            }
            IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);

            diff.Diff();
            return(new Status(diff));
        }
Example #8
0
        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);
            }
        }
 /// <summary>
 /// Executes the
 /// <code>Status</code>
 /// command with all the options and parameters
 /// collected by the setter methods of this class. Each instance of this
 /// class should only be used for one invocation of the command. Don't call
 /// this method twice on an instance.
 /// </summary>
 /// <returns>
 /// a
 /// <see cref="Status">Status</see>
 /// object telling about each path where working
 /// tree, index or HEAD differ from each other.
 /// </returns>
 /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
 /// <exception cref="NGit.Errors.NoWorkTreeException"></exception>
 public override Status Call()
 {
     if (workingTreeIt == null)
     {
         workingTreeIt = new FileTreeIterator(repo);
     }
     try
     {
         IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);
         diff.Diff();
         return(new Status(diff));
     }
     catch (IOException e)
     {
         throw new JGitInternalException(e.Message, e);
     }
 }
Example #10
0
        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);
        }
Example #11
0
        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 override NGit.Api.Status Call()
        {
            if (iter == null)
            {
                iter = new FileTreeIterator(repo);
            }

            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));
        }
Example #13
0
        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);
        }
Example #14
0
        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);
        }
Example #15
0
 /// <param name="diff"></param>
 public Status(IndexDiff diff) : base()
 {
     this.diff = diff;
 }
Example #16
0
        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);
        }
Example #17
0
        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);
        }
Example #18
0
        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);
        }
Example #19
0
        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);
        }