Merge branch 'zh/pretty-date-human'
[alt-git.git] / t / t8002-blame.sh
blob5bb302b1ba0f36eff7c3bd64a4a0dd690a135559
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-lib.sh
9 PROG='git blame -c'
10 . "$TEST_DIRECTORY"/annotate-tests.sh
12 test_expect_success 'setup' '
13 hexsz=$(test_oid hexsz)
16 test_expect_success 'blame untracked file in empty repo' '
17 >untracked &&
18 test_must_fail git blame untracked
21 PROG='git blame -c -e'
22 test_expect_success 'blame --show-email' '
23 check_count \
24 "<A@test.git>" 1 \
25 "<B@test.git>" 1 \
26 "<B1@test.git>" 1 \
27 "<B2@test.git>" 1 \
28 "<author@example.com>" 1 \
29 "<C@test.git>" 1 \
30 "<D@test.git>" 1 \
31 "<E at test dot git>" 1
34 test_expect_success 'setup showEmail tests' '
35 echo "bin: test number 1" >one &&
36 git add one &&
37 GIT_AUTHOR_NAME=name1 \
38 GIT_AUTHOR_EMAIL=email1@test.git \
39 git commit -m First --date="2010-01-01 01:00:00" &&
40 cat >expected_n <<-\EOF &&
41 (name1 2010-01-01 01:00:00 +0000 1) bin: test number 1
42 EOF
43 cat >expected_e <<-\EOF
44 (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
45 EOF
48 find_blame () {
49 sed -e 's/^[^(]*//'
52 test_expect_success 'blame with no options and no config' '
53 git blame one >blame &&
54 find_blame <blame >result &&
55 test_cmp expected_n result
58 test_expect_success 'blame with showemail options' '
59 git blame --show-email one >blame1 &&
60 find_blame <blame1 >result &&
61 test_cmp expected_e result &&
62 git blame -e one >blame2 &&
63 find_blame <blame2 >result &&
64 test_cmp expected_e result &&
65 git blame --no-show-email one >blame3 &&
66 find_blame <blame3 >result &&
67 test_cmp expected_n result
70 test_expect_success 'blame with showEmail config false' '
71 git config blame.showEmail false &&
72 git blame one >blame1 &&
73 find_blame <blame1 >result &&
74 test_cmp expected_n result &&
75 git blame --show-email one >blame2 &&
76 find_blame <blame2 >result &&
77 test_cmp expected_e result &&
78 git blame -e one >blame3 &&
79 find_blame <blame3 >result &&
80 test_cmp expected_e result &&
81 git blame --no-show-email one >blame4 &&
82 find_blame <blame4 >result &&
83 test_cmp expected_n result
86 test_expect_success 'blame with showEmail config true' '
87 git config blame.showEmail true &&
88 git blame one >blame1 &&
89 find_blame <blame1 >result &&
90 test_cmp expected_e result &&
91 git blame --no-show-email one >blame2 &&
92 find_blame <blame2 >result &&
93 test_cmp expected_n result
96 test_expect_success 'set up abbrev tests' '
97 test_commit abbrev &&
98 sha1=$(git rev-parse --verify HEAD) &&
99 check_abbrev () {
100 expect=$1; shift
101 echo $sha1 | cut -c 1-$expect >expect &&
102 git blame "$@" abbrev.t >actual &&
103 perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
104 test_cmp expect actual.sha
108 test_expect_success 'blame --abbrev=<n> works' '
109 # non-boundary commits get +1 for alignment
110 check_abbrev 31 --abbrev=30 HEAD &&
111 check_abbrev 30 --abbrev=30 ^HEAD
114 test_expect_success 'blame -l aligns regular and boundary commits' '
115 check_abbrev $hexsz -l HEAD &&
116 check_abbrev $((hexsz - 1)) -l ^HEAD
119 test_expect_success 'blame --abbrev with full length behaves like -l' '
120 check_abbrev $hexsz --abbrev=$hexsz HEAD &&
121 check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
124 test_expect_success '--no-abbrev works like --abbrev with full length' '
125 check_abbrev $hexsz --no-abbrev
128 test_expect_success '--exclude-promisor-objects does not BUG-crash' '
129 test_must_fail git blame --exclude-promisor-objects one
132 test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
133 git init server &&
134 echo foo >server/file.txt &&
135 git -C server add file.txt &&
136 git -C server commit -m file &&
138 git clone --filter=blob:none "file://$(pwd)/server" client &&
139 echo bar >>client/file.txt &&
140 git -C client blame file.txt
143 test_done