Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t8002-blame.sh
blob35966340397591eee54a0f82d00eed70b3814e98
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 PROG='git blame -c'
12 . "$TEST_DIRECTORY"/annotate-tests.sh
14 test_expect_success 'setup' '
15 hexsz=$(test_oid hexsz)
18 test_expect_success 'blame untracked file in empty repo' '
19 >untracked &&
20 test_must_fail git blame untracked
23 PROG='git blame -c -e'
24 test_expect_success 'blame --show-email' '
25 check_count \
26 "<A@test.git>" 1 \
27 "<B@test.git>" 1 \
28 "<B1@test.git>" 1 \
29 "<B2@test.git>" 1 \
30 "<author@example.com>" 1 \
31 "<C@test.git>" 1 \
32 "<D@test.git>" 1 \
33 "<E at test dot git>" 1
36 test_expect_success 'setup showEmail tests' '
37 echo "bin: test number 1" >one &&
38 git add one &&
39 GIT_AUTHOR_NAME=name1 \
40 GIT_AUTHOR_EMAIL=email1@test.git \
41 git commit -m First --date="2010-01-01 01:00:00" &&
42 cat >expected_n <<-\EOF &&
43 (name1 2010-01-01 01:00:00 +0000 1) bin: test number 1
44 EOF
45 cat >expected_e <<-\EOF
46 (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
47 EOF
50 find_blame () {
51 sed -e 's/^[^(]*//'
54 test_expect_success 'blame with no options and no config' '
55 git blame one >blame &&
56 find_blame <blame >result &&
57 test_cmp expected_n result
60 test_expect_success 'blame with showemail options' '
61 git blame --show-email one >blame1 &&
62 find_blame <blame1 >result &&
63 test_cmp expected_e result &&
64 git blame -e one >blame2 &&
65 find_blame <blame2 >result &&
66 test_cmp expected_e result &&
67 git blame --no-show-email one >blame3 &&
68 find_blame <blame3 >result &&
69 test_cmp expected_n result
72 test_expect_success 'blame with showEmail config false' '
73 git config blame.showEmail false &&
74 git blame one >blame1 &&
75 find_blame <blame1 >result &&
76 test_cmp expected_n result &&
77 git blame --show-email one >blame2 &&
78 find_blame <blame2 >result &&
79 test_cmp expected_e result &&
80 git blame -e one >blame3 &&
81 find_blame <blame3 >result &&
82 test_cmp expected_e result &&
83 git blame --no-show-email one >blame4 &&
84 find_blame <blame4 >result &&
85 test_cmp expected_n result
88 test_expect_success 'blame with showEmail config true' '
89 git config blame.showEmail true &&
90 git blame one >blame1 &&
91 find_blame <blame1 >result &&
92 test_cmp expected_e result &&
93 git blame --no-show-email one >blame2 &&
94 find_blame <blame2 >result &&
95 test_cmp expected_n result
98 test_expect_success 'set up abbrev tests' '
99 test_commit abbrev &&
100 sha1=$(git rev-parse --verify HEAD) &&
101 check_abbrev () {
102 expect=$1 && shift &&
103 echo $sha1 | cut -c 1-$expect >expect &&
104 git blame "$@" abbrev.t >actual &&
105 perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
106 test_cmp expect actual.sha
110 test_expect_success 'blame --abbrev=<n> works' '
111 # non-boundary commits get +1 for alignment
112 check_abbrev 31 --abbrev=30 HEAD &&
113 check_abbrev 30 --abbrev=30 ^HEAD
116 test_expect_success 'blame -l aligns regular and boundary commits' '
117 check_abbrev $hexsz -l HEAD &&
118 check_abbrev $((hexsz - 1)) -l ^HEAD
121 test_expect_success 'blame --abbrev with full length behaves like -l' '
122 check_abbrev $hexsz --abbrev=$hexsz HEAD &&
123 check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
126 test_expect_success '--no-abbrev works like --abbrev with full length' '
127 check_abbrev $hexsz --no-abbrev
130 test_expect_success '--exclude-promisor-objects does not BUG-crash' '
131 test_must_fail git blame --exclude-promisor-objects one
134 test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
135 git init server &&
136 echo foo >server/file.txt &&
137 git -C server add file.txt &&
138 git -C server commit -m file &&
140 git clone --filter=blob:none "file://$(pwd)/server" client &&
141 echo bar >>client/file.txt &&
142 git -C client blame file.txt
145 test_done