Start the 2.46 cycle
[git.git] / t / t8002-blame.sh
blob0147de304b4d104cc7f05ea1f8d68f1a07ceb80d
1 #!/bin/sh
3 test_description='git blame'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_CREATE_REPO_NO_TEMPLATE=1
8 . ./test-lib.sh
10 PROG='git blame -c'
11 . "$TEST_DIRECTORY"/annotate-tests.sh
13 test_expect_success 'setup' '
14 hexsz=$(test_oid hexsz)
17 test_expect_success 'blame untracked file in empty repo' '
18 >untracked &&
19 test_must_fail git blame untracked
22 PROG='git blame -c -e'
23 test_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
35 test_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
49 find_blame () {
50 sed -e 's/^[^(]*//'
53 test_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
59 test_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
71 test_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
87 test_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
97 test_expect_success 'set up abbrev tests' '
98 test_commit abbrev &&
99 sha1=$(git rev-parse --verify HEAD) &&
100 check_abbrev () {
101 expect=$1 && shift &&
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
109 test_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
115 test_expect_success 'blame -l aligns regular and boundary commits' '
116 check_abbrev $hexsz -l HEAD &&
117 check_abbrev $((hexsz - 1)) -l ^HEAD
120 test_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
125 test_expect_success '--no-abbrev works like --abbrev with full length' '
126 check_abbrev $hexsz --no-abbrev
129 test_expect_success '--exclude-promisor-objects does not BUG-crash' '
130 test_must_fail git blame --exclude-promisor-objects one
133 test_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 &&
139 git clone --filter=blob:none "file://$(pwd)/server" client &&
140 echo bar >>client/file.txt &&
141 git -C client blame file.txt
144 test_done