Пример #1
0
        public virtual void TestTwoRevisions()
        {
            Git git = new Git(db);

            string[] content1 = new string[] { "first", "second" };
            WriteTrashFile("file.txt", Join(content1));
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit commit1 = git.Commit().SetMessage("create file").Call();

            string[] content2 = new string[] { "first", "second", "third" };
            WriteTrashFile("file.txt", Join(content2));
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit    commit2 = git.Commit().SetMessage("create file").Call();
            BlameCommand command = new BlameCommand(db);

            command.SetFilePath("file.txt");
            BlameResult lines = command.Call();

            NUnit.Framework.Assert.AreEqual(3, lines.GetResultContents().Size());
            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0));
            NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0));
            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(1));
            NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1));
            NUnit.Framework.Assert.AreEqual(commit2, lines.GetSourceCommit(2));
            NUnit.Framework.Assert.AreEqual(2, lines.GetSourceLine(2));
        }
Пример #2
0
        public virtual void TestMiddleClearAllLines()
        {
            Git git = new Git(db);

            string[] content1 = new string[] { "a", "b", "c" };
            WriteTrashFile("file.txt", Join(content1));
            git.Add().AddFilepattern("file.txt").Call();
            git.Commit().SetMessage("edit file").Call();
            WriteTrashFile("file.txt", string.Empty);
            git.Add().AddFilepattern("file.txt").Call();
            git.Commit().SetMessage("create file").Call();
            WriteTrashFile("file.txt", Join(content1));
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit    commit3 = git.Commit().SetMessage("edit file").Call();
            BlameCommand command = new BlameCommand(db);

            command.SetFilePath("file.txt");
            BlameResult lines = command.Call();

            NUnit.Framework.Assert.AreEqual(content1.Length, lines.GetResultContents().Size()
                                            );
            NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(0));
            NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(1));
            NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(2));
        }
Пример #3
0
        public virtual void TestDeleteMiddleLines()
        {
            Git git = new Git(db);

            string[] content1 = new string[] { "a", "b", "c", "d", "e" };
            string[] content2 = new string[] { "a", "c", "e" };
            WriteTrashFile("file.txt", Join(content2));
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit commit1 = git.Commit().SetMessage("edit file").Call();

            WriteTrashFile("file.txt", Join(content1));
            git.Add().AddFilepattern("file.txt").Call();
            git.Commit().SetMessage("edit file").Call();
            WriteTrashFile("file.txt", Join(content2));
            git.Add().AddFilepattern("file.txt").Call();
            git.Commit().SetMessage("edit file").Call();
            BlameCommand command = new BlameCommand(db);

            command.SetFilePath("file.txt");
            BlameResult lines = command.Call();

            NUnit.Framework.Assert.AreEqual(content2.Length, lines.GetResultContents().Size()
                                            );
            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0));
            NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0));
            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(1));
            NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1));
            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(2));
            NUnit.Framework.Assert.AreEqual(2, lines.GetSourceLine(2));
        }
Пример #4
0
        /// <exception cref="System.Exception"></exception>
        private void TestRename(string sourcePath, string destPath)
        {
            Git git = new Git(db);

            string[] content1 = new string[] { "a", "b", "c" };
            WriteTrashFile(sourcePath, Join(content1));
            git.Add().AddFilepattern(sourcePath).Call();
            RevCommit commit1 = git.Commit().SetMessage("create file").Call();

            WriteTrashFile(destPath, Join(content1));
            git.Add().AddFilepattern(destPath).Call();
            git.Rm().AddFilepattern(sourcePath).Call();
            git.Commit().SetMessage("moving file").Call();
            string[] content2 = new string[] { "a", "b", "c2" };
            WriteTrashFile(destPath, Join(content2));
            git.Add().AddFilepattern(destPath).Call();
            RevCommit    commit3 = git.Commit().SetMessage("editing file").Call();
            BlameCommand command = new BlameCommand(db);

            command.SetFollowFileRenames(true);
            command.SetFilePath(destPath);
            BlameResult lines = command.Call();

            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0));
            NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0));
            NUnit.Framework.Assert.AreEqual(sourcePath, lines.GetSourcePath(0));
            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(1));
            NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1));
            NUnit.Framework.Assert.AreEqual(sourcePath, lines.GetSourcePath(1));
            NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(2));
            NUnit.Framework.Assert.AreEqual(2, lines.GetSourceLine(2));
            NUnit.Framework.Assert.AreEqual(destPath, lines.GetSourcePath(2));
        }
Пример #5
0
        public virtual void TestSingleRevision()
        {
            Git git = new Git(db);

            string[] content = new string[] { "first", "second", "third" };
            WriteTrashFile("file.txt", Join(content));
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit    commit  = git.Commit().SetMessage("create file").Call();
            BlameCommand command = new BlameCommand(db);

            command.SetFilePath("file.txt");
            BlameResult lines = command.Call();

            NUnit.Framework.Assert.IsNotNull(lines);
            NUnit.Framework.Assert.AreEqual(3, lines.GetResultContents().Size());
            for (int i = 0; i < 3; i++)
            {
                NUnit.Framework.Assert.AreEqual(commit, lines.GetSourceCommit(i));
                NUnit.Framework.Assert.AreEqual(i, lines.GetSourceLine(i));
            }
        }
Пример #6
0
        public virtual void TestTwoRenames()
        {
            Git git = new Git(db);

            // Commit 1: Add file.txt
            string[] content1 = new string[] { "a" };
            WriteTrashFile("file.txt", Join(content1));
            git.Add().AddFilepattern("file.txt").Call();
            RevCommit commit1 = git.Commit().SetMessage("create file").Call();

            // Commit 2: Rename to file1.txt
            WriteTrashFile("file1.txt", Join(content1));
            git.Add().AddFilepattern("file1.txt").Call();
            git.Rm().AddFilepattern("file.txt").Call();
            git.Commit().SetMessage("moving file").Call();
            // Commit 3: Edit file1.txt
            string[] content2 = new string[] { "a", "b" };
            WriteTrashFile("file1.txt", Join(content2));
            git.Add().AddFilepattern("file1.txt").Call();
            RevCommit commit3 = git.Commit().SetMessage("editing file").Call();

            // Commit 4: Rename to file2.txt
            WriteTrashFile("file2.txt", Join(content2));
            git.Add().AddFilepattern("file2.txt").Call();
            git.Rm().AddFilepattern("file1.txt").Call();
            git.Commit().SetMessage("moving file again").Call();
            BlameCommand command = new BlameCommand(db);

            command.SetFollowFileRenames(true);
            command.SetFilePath("file2.txt");
            BlameResult lines = command.Call();

            NUnit.Framework.Assert.AreEqual(commit1, lines.GetSourceCommit(0));
            NUnit.Framework.Assert.AreEqual(0, lines.GetSourceLine(0));
            NUnit.Framework.Assert.AreEqual("file.txt", lines.GetSourcePath(0));
            NUnit.Framework.Assert.AreEqual(commit3, lines.GetSourceCommit(1));
            NUnit.Framework.Assert.AreEqual(1, lines.GetSourceLine(1));
            NUnit.Framework.Assert.AreEqual("file1.txt", lines.GetSourcePath(1));
        }