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