Raw
1 #!/bin/sh
2
3 test_description='colored git blame'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 TEST_CREATE_REPO_NO_TEMPLATE=1
8 . ./test-lib.sh
9
10 if ! test_have_prereq PERL_TEST_HELPERS
11 then
12 skip_all='skipping blame colors tests; Perl not available'
13 test_done
14 fi
15
16 PROG='git blame -c'
17 . "$TEST_DIRECTORY"/annotate-tests.sh
18
19 test_expect_success 'colored blame colors contiguous lines' '
20 git -c color.blame.repeatedLines=yellow blame --color-lines --abbrev=12 hello.c >actual.raw &&
21 git -c color.blame.repeatedLines=yellow -c blame.coloring=repeatedLines blame --abbrev=12 hello.c >actual.raw.2 &&
22 test_cmp actual.raw actual.raw.2 &&
23 test_decode_color <actual.raw >actual &&
24 grep "<YELLOW>" <actual >darkened &&
25 grep "(F" darkened > F.expect &&
26 grep "(H" darkened > H.expect &&
27 test_line_count = 2 F.expect &&
28 test_line_count = 3 H.expect
29 '
30
31 test_expect_success 'color lines becoming contiguous due to --ignore-rev' '
32 mv hello.c hello.orig &&
33 sed "s/ / /g" <hello.orig >hello.c &&
34 git add hello.c &&
35 git commit -m"tabs to spaces" &&
36 git -c color.blame.repeatedLines=yellow blame --color-lines --ignore-rev=HEAD hello.c >actual.raw &&
37 test_decode_color <actual.raw >actual &&
38 grep "<YELLOW>" <actual >darkened &&
39 grep "(F" darkened > F.expect &&
40 grep "(H" darkened > H.expect &&
41 test_line_count = 2 F.expect &&
42 test_line_count = 3 H.expect
43 '
44
45 test_expect_success 'color by age consistently colors old code' '
46 git blame --color-by-age hello.c >actual.raw &&
47 git -c blame.coloring=highlightRecent blame hello.c >actual.raw.2 &&
48 test_cmp actual.raw actual.raw.2 &&
49 test_decode_color <actual.raw >actual &&
50 grep "<BLUE>" <actual >colored &&
51 test_line_count = 10 colored
52 '
53
54 test_expect_success 'blame color by age: new code is different' '
55 cat >>hello.c <<-EOF &&
56 void qfunc();
57 EOF
58 git add hello.c &&
59 GIT_AUTHOR_DATE="" git commit -m "new commit" &&
60
61 git -c color.blame.highlightRecent="yellow,1 month ago, cyan" blame --color-by-age hello.c >actual.raw &&
62 test_decode_color <actual.raw >actual &&
63
64 grep "<YELLOW>" <actual >colored &&
65 test_line_count = 10 colored &&
66
67 grep "<CYAN>" <actual >colored &&
68 test_line_count = 1 colored &&
69 test_grep qfunc colored
70 '
71
72 test_done