interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t8002-blame.sh

173 lines · 4617 bytes Raw Blame History
1#!/bin/sh
2
3test_description='git blame'
4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7TEST_CREATE_REPO_NO_TEMPLATE=1
8. ./test-lib.sh
9
10if ! test_have_prereq PERL_TEST_HELPERS
11then
12 skip_all='skipping blame colors tests; Perl not available'
13 test_done
14fi
15
16PROG='git blame -c'
17. "$TEST_DIRECTORY"/annotate-tests.sh
18
19test_expect_success 'setup' '
20 hexsz=$(test_oid hexsz)
21'
22
23test_expect_success 'blame untracked file in empty repo' '
24 >untracked &&
25 test_must_fail git blame untracked
26'
27
28PROG='git blame -c -e'
29test_expect_success 'blame --show-email' '
30 check_count \
31 "<A@test.git>" 1 \
32 "<B@test.git>" 1 \
33 "<B1@test.git>" 1 \
34 "<B2@test.git>" 1 \
35 "<author@example.com>" 1 \
36 "<C@test.git>" 1 \
37 "<D@test.git>" 1 \
38 "<E at test dot git>" 1
39'
40
41test_expect_success 'setup showEmail tests' '
42 echo "bin: test number 1" >one &&
43 git add one &&
44 GIT_AUTHOR_NAME=name1 \
45 GIT_AUTHOR_EMAIL=email1@test.git \
46 git commit -m First --date="2010-01-01 01:00:00" &&
47 cat >expected_n <<-\EOF &&
48 (name1 2010-01-01 01:00:00 +0000 1) bin: test number 1
49 EOF
50 cat >expected_e <<-\EOF
51 (<email1@test.git> 2010-01-01 01:00:00 +0000 1) bin: test number 1
52 EOF
53'
54
55find_blame () {
56 sed -e 's/^[^(]*//'
57}
58
59test_expect_success 'blame with no options and no config' '
60 git blame one >blame &&
61 find_blame <blame >result &&
62 test_cmp expected_n result
63'
64
65test_expect_success 'blame with showemail options' '
66 git blame --show-email one >blame1 &&
67 find_blame <blame1 >result &&
68 test_cmp expected_e result &&
69 git blame -e one >blame2 &&
70 find_blame <blame2 >result &&
71 test_cmp expected_e result &&
72 git blame --no-show-email one >blame3 &&
73 find_blame <blame3 >result &&
74 test_cmp expected_n result
75'
76
77test_expect_success 'blame with showEmail config false' '
78 git config blame.showEmail false &&
79 git blame one >blame1 &&
80 find_blame <blame1 >result &&
81 test_cmp expected_n result &&
82 git blame --show-email one >blame2 &&
83 find_blame <blame2 >result &&
84 test_cmp expected_e result &&
85 git blame -e one >blame3 &&
86 find_blame <blame3 >result &&
87 test_cmp expected_e result &&
88 git blame --no-show-email one >blame4 &&
89 find_blame <blame4 >result &&
90 test_cmp expected_n result
91'
92
93test_expect_success 'blame with showEmail config true' '
94 git config blame.showEmail true &&
95 git blame one >blame1 &&
96 find_blame <blame1 >result &&
97 test_cmp expected_e result &&
98 git blame --no-show-email one >blame2 &&
99 find_blame <blame2 >result &&
100 test_cmp expected_n result
101'
102
103test_expect_success 'set up abbrev tests' '
104 test_commit abbrev &&
105 sha1=$(git rev-parse --verify HEAD) &&
106 check_abbrev () {
107 expect=$1 && shift &&
108 echo $sha1 | cut -c 1-$expect >expect &&
109 git blame "$@" abbrev.t >actual &&
110 sed -n "s/^[\^]\{0,1\}\([0-9a-f][0-9a-f]*\).*/\1/p" actual >actual.sha &&
111 test_cmp expect actual.sha
112 }
113'
114
115test_expect_success 'blame --abbrev=<n> works' '
116 check_abbrev 30 --abbrev=30 HEAD &&
117 check_abbrev 30 --abbrev=30 ^HEAD
118'
119
120test_expect_success 'blame -l aligns regular and boundary commits' '
121 check_abbrev $hexsz -l HEAD &&
122 check_abbrev $((hexsz - 1)) -l ^HEAD
123'
124
125test_expect_success 'blame --abbrev with full length behaves like -l' '
126 check_abbrev $hexsz --abbrev=$hexsz HEAD &&
127 check_abbrev $((hexsz - 1)) --abbrev=$hexsz ^HEAD
128'
129
130test_expect_success '--no-abbrev works like --abbrev with full length' '
131 check_abbrev $hexsz --no-abbrev
132'
133
134test_expect_success 'blame --abbrev gets truncated' '
135 check_abbrev $hexsz --abbrev=9000 HEAD
136'
137
138test_expect_success 'blame --abbrev gets truncated with boundary commit' '
139 check_abbrev $hexsz --abbrev=9000 ^HEAD
140'
141
142test_expect_success 'blame --abbrev -b truncates the blank boundary' '
143 cat >expect <<-EOF &&
144 $(printf "%10s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
145 EOF
146 git blame -b --abbrev=10 ^HEAD -- abbrev.t >actual &&
147 test_cmp expect actual
148'
149
150test_expect_success 'blame with excessive --abbrev and -b culls to hash length' '
151 cat >expect <<-EOF &&
152 $(printf "%${hexsz}s" "") (<author@example.com> 2005-04-07 15:45:13 -0700 1) abbrev
153 EOF
154 git blame -b --abbrev=9000 ^HEAD -- abbrev.t >actual &&
155 test_cmp expect actual
156'
157
158test_expect_success '--exclude-promisor-objects does not BUG-crash' '
159 test_must_fail git blame --exclude-promisor-objects one
160'
161
162test_expect_success 'blame with uncommitted edits in partial clone does not crash' '
163 git init server &&
164 echo foo >server/file.txt &&
165 git -C server add file.txt &&
166 git -C server commit -m file &&
167
168 git clone --filter=blob:none "file://$(pwd)/server" client &&
169 echo bar >>client/file.txt &&
170 git -C client blame file.txt
171'
172
173test_done