]> git.ipfire.org Git - thirdparty/git.git/blame - t/t8002-blame.sh
Merge branch 'ea/blame-use-oideq'
[thirdparty/git.git] / t / t8002-blame.sh
CommitLineData
8752d11d
FK
1#!/bin/sh
2
5be60078 3test_description='git blame'
8752d11d
FK
4. ./test-lib.sh
5
6PROG='git blame -c'
bfdbee98 7. "$TEST_DIRECTORY"/annotate-tests.sh
8752d11d 8
98de0b27 9test_expect_success 'setup' '
10 hexsz=$(test_oid hexsz)
11'
12
bc6b13a7
TG
13test_expect_success 'blame untracked file in empty repo' '
14 >untracked &&
15 test_must_fail git blame untracked
16'
17
1b8cdce9 18PROG='git blame -c -e'
e37f39c1
ES
19test_expect_success 'blame --show-email' '
20 check_count \
21 "<A@test.git>" 1 \
22 "<B@test.git>" 1 \
23 "<B1@test.git>" 1 \
24 "<B2@test.git>" 1 \
25 "<author@example.com>" 1 \
26 "<C@test.git>" 1 \
27 "<D@test.git>" 1 \
28 "<E at test dot git>" 1
1b8cdce9
KB
29'
30
8b504db3
QN
31test_expect_success 'setup showEmail tests' '
32 echo "bin: test number 1" >one &&
33 git add one &&
34 GIT_AUTHOR_NAME=name1 \
35 GIT_AUTHOR_EMAIL=email1@test.git \
36 git commit -m First --date="2010-01-01 01:00:00" &&
37 cat >expected_n <<-\EOF &&
38 (name1 2010-01-01 01:00:00 +0000 1) bin: test number 1
39 EOF
40 cat >expected_e <<-\EOF
41 (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
42 EOF
43'
44
45find_blame () {
46 sed -e 's/^[^(]*//'
47}
48
49test_expect_success 'blame with no options and no config' '
50 git blame one >blame &&
51 find_blame <blame >result &&
52 test_cmp expected_n result
53'
54
55test_expect_success 'blame with showemail options' '
56 git blame --show-email one >blame1 &&
57 find_blame <blame1 >result &&
58 test_cmp expected_e result &&
59 git blame -e one >blame2 &&
60 find_blame <blame2 >result &&
61 test_cmp expected_e result &&
62 git blame --no-show-email one >blame3 &&
63 find_blame <blame3 >result &&
64 test_cmp expected_n result
65'
66
67test_expect_success 'blame with showEmail config false' '
68 git config blame.showEmail false &&
69 git blame one >blame1 &&
70 find_blame <blame1 >result &&
71 test_cmp expected_n result &&
72 git blame --show-email one >blame2 &&
73 find_blame <blame2 >result &&
74 test_cmp expected_e result &&
75 git blame -e one >blame3 &&
76 find_blame <blame3 >result &&
77 test_cmp expected_e result &&
78 git blame --no-show-email one >blame4 &&
79 find_blame <blame4 >result &&
80 test_cmp expected_n result
81'
82
83test_expect_success 'blame with showEmail config true' '
84 git config blame.showEmail true &&
85 git blame one >blame1 &&
86 find_blame <blame1 >result &&
87 test_cmp expected_e result &&
88 git blame --no-show-email one >blame2 &&
89 find_blame <blame2 >result &&
90 test_cmp expected_n result
91'
92
91229834
JK
93test_expect_success 'set up abbrev tests' '
94 test_commit abbrev &&
95 sha1=$(git rev-parse --verify HEAD) &&
96 check_abbrev () {
97 expect=$1; shift
98 echo $sha1 | cut -c 1-$expect >expect &&
99 git blame "$@" abbrev.t >actual &&
100 perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
101 test_cmp expect actual.sha
102 }
103'
104
105test_expect_success 'blame --abbrev=<n> works' '
106 # non-boundary commits get +1 for alignment
107 check_abbrev 31 --abbrev=30 HEAD &&
108 check_abbrev 30 --abbrev=30 ^HEAD
109'
110
111test_expect_success 'blame -l aligns regular and boundary commits' '
98de0b27 112 check_abbrev $hexsz -l HEAD &&
113 check_abbrev $((hexsz - 1)) -l ^HEAD
91229834
JK
114'
115
98de0b27 116test_expect_success 'blame --abbrev with full length behaves like -l' '
117 check_abbrev $hexsz --abbrev=$hexsz HEAD &&
118 check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
91229834
JK
119'
120
98de0b27 121test_expect_success '--no-abbrev works like --abbrev with full length' '
122 check_abbrev $hexsz --no-abbrev
ed58d808
JK
123'
124
669b1d2a
MD
125test_expect_success '--exclude-promisor-objects does not BUG-crash' '
126 test_must_fail git blame --exclude-promisor-objects one
127'
128
a64d2aae
JT
129test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
130 git init server &&
131 echo foo >server/file.txt &&
132 git -C server add file.txt &&
133 git -C server commit -m file &&
134
135 git clone --filter=blob:none "file://$(pwd)/server" client &&
136 echo bar >>client/file.txt &&
137 git -C client blame file.txt
138'
139
8752d11d 140test_done