Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BlameFixture.cs « LibGit2Sharp.Tests - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b0fcf77fe79ad5642e5e5766e74da91538dbc691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;

namespace LibGit2Sharp.Tests
{
    public class BlameFixture : BaseFixture
    {
        private static void AssertCorrectHeadBlame(BlameHunkCollection blame)
        {
            Assert.Equal(1, blame.Count());
            Assert.Equal(0, blame[0].FinalStartLineNumber);
            Assert.Equal("schacon@gmail.com", blame[0].FinalSignature.Email);
            Assert.Equal("4a202b3", blame[0].FinalCommit.Id.ToString(7));

            Assert.Equal(0, blame.HunkForLine(0).FinalStartLineNumber);
            Assert.Equal("schacon@gmail.com", blame.HunkForLine(0).FinalSignature.Email);
            Assert.Equal("4a202b3", blame.HunkForLine(0).FinalCommit.Id.ToString(7));
        }

        [Fact]
        public void CanBlameSimply()
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                AssertCorrectHeadBlame(repo.Blame("README"));
            }
        }

        [Fact]
        public void CanBlameFromADifferentCommit()
        {
            using (var repo = new Repository(MergedTestRepoWorkingDirPath))
            {
                // File doesn't exist at HEAD
                Assert.Throws<LibGit2SharpException>(() => repo.Blame("ancestor-only.txt"));

                var blame = repo.Blame("ancestor-only.txt", new BlameOptions { StartingAt = "9107b30" });
                Assert.Equal(1, blame.Count());
            }
        }

        [Fact]
        public void ValidatesLimits()
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                var blame = repo.Blame("README");

                Assert.Throws<ArgumentOutOfRangeException>(() => blame[1]);
                Assert.Throws<ArgumentOutOfRangeException>(() => blame.HunkForLine(2));
            }
        }

        [Fact]
        public void CanBlameFromVariousTypes()
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = "HEAD" }));
                AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Head }));
                AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Head.Tip }));
                AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Branches["master"]}));
            }
        }

        [Fact]
        public void CanStopBlame()
        {
            using (var repo = new Repository(BareTestRepoPath))
            {
                // $ git blame .\new.txt
                // 9fd738e8 (Scott Chacon 2010-05-24 10:19:19 -0700 1) my new file
                // (be3563a comes after 9fd738e8)
                var blame = repo.Blame("new.txt", new BlameOptions {StoppingAt = "be3563a"});
                Assert.True(blame[0].FinalCommit.Sha.StartsWith("be3563a"));
            }
        }
    }
}