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
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' '
19 test_must_fail git blame untracked
22 PROG
='git blame -c -e'
23 test_expect_success
'blame --show-email' '
29 "<author@example.com>" 1 \
32 "<E at test dot git>" 1
35 test_expect_success
'setup showEmail tests' '
36 echo "bin: test number 1" >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
44 cat >expected_e <<-\EOF
45 (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
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' '
99 sha1=$(git rev-parse --verify HEAD) &&
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' '
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