3 # Copyright (c) 2010, Will Palmer
4 # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
7 test_description
='Test pretty formats'
10 # Tested non-UTF-8 encoding
11 test_encoding
="ISO8859-1"
13 sample_utf8_part
=$
(printf "f\303\244ng")
16 # String "initial. initial" partly in German
17 # (translated with Google Translate),
18 # encoded in UTF-8, used as a commit log message below.
19 msg
="initial. an${sample_utf8_part}lich\n"
22 printf "$msg" |
iconv -f utf-8
-t "$1"
28 test_expect_success
'set up basic repos' '
33 git config i18n.commitEncoding $test_encoding &&
34 git commit -m "$(commit_msg $test_encoding)" &&
37 git commit -m "add bar" &&
38 git config --unset i18n.commitEncoding
41 test_expect_success
'alias builtin format' '
42 git log --pretty=oneline >expected &&
43 git config pretty.test-alias oneline &&
44 git log --pretty=test-alias >actual &&
45 test_cmp expected actual
48 test_expect_success
'alias masking builtin format' '
49 git log --pretty=oneline >expected &&
50 git config pretty.oneline "%H" &&
51 git log --pretty=oneline >actual &&
52 test_cmp expected actual
55 test_expect_success
'alias user-defined format' '
56 git log --pretty="format:%h" >expected &&
57 git config pretty.test-alias "format:%h" &&
58 git log --pretty=test-alias >actual &&
59 test_cmp expected actual
62 test_expect_success
'alias user-defined tformat with %s (ISO8859-1 encoding)' '
63 git config i18n.logOutputEncoding $test_encoding &&
64 git log --oneline >expected-s &&
65 git log --pretty="tformat:%h %s" >actual-s &&
66 git config --unset i18n.logOutputEncoding &&
67 test_cmp expected-s actual-s
70 test_expect_success
'alias user-defined tformat with %s (utf-8 encoding)' '
71 git log --oneline >expected-s &&
72 git log --pretty="tformat:%h %s" >actual-s &&
73 test_cmp expected-s actual-s
76 test_expect_success
'alias user-defined tformat' '
77 git log --pretty="tformat:%h" >expected &&
78 git config pretty.test-alias "tformat:%h" &&
79 git log --pretty=test-alias >actual &&
80 test_cmp expected actual
83 test_expect_success
'alias non-existent format' '
84 git config pretty.test-alias format-that-will-never-exist &&
85 test_must_fail git log --pretty=test-alias
88 test_expect_success
'alias of an alias' '
89 git log --pretty="tformat:%h" >expected &&
90 git config pretty.test-foo "tformat:%h" &&
91 git config pretty.test-bar test-foo &&
92 git log --pretty=test-bar >actual && test_cmp expected actual
95 test_expect_success
'alias masking an alias' '
96 git log --pretty=format:"Two %H" >expected &&
97 git config pretty.duplicate "format:One %H" &&
98 git config --add pretty.duplicate "format:Two %H" &&
99 git log --pretty=duplicate >actual &&
100 test_cmp expected actual
103 test_expect_success
'alias loop' '
104 git config pretty.test-foo test-bar &&
105 git config pretty.test-bar test-foo &&
106 test_must_fail git log --pretty=test-foo
109 test_expect_success
'NUL separation' '
110 printf "add bar\0$(commit_msg)" >expected &&
111 git log -z --pretty="format:%s" >actual &&
112 test_cmp expected actual
115 test_expect_success
'NUL termination' '
116 printf "add bar\0$(commit_msg)\0" >expected &&
117 git log -z --pretty="tformat:%s" >actual &&
118 test_cmp expected actual
121 test_expect_success
'NUL separation with --stat' '
122 stat0_part=$(git diff --stat HEAD^ HEAD) &&
123 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
124 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
125 git log -z --stat --pretty="format:%s" >actual &&
126 test_i18ncmp expected actual
129 test_expect_failure
'NUL termination with --stat' '
130 stat0_part=$(git diff --stat HEAD^ HEAD) &&
131 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
132 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
133 git log -z --stat --pretty="tformat:%s" >actual &&
134 test_i18ncmp expected actual
137 test_expect_success
'setup more commits' '
138 test_commit "message one" one one message-one &&
139 test_commit "message two" two two message-two &&
140 head1=$(git rev-parse --verify --short HEAD~0) &&
141 head2=$(git rev-parse --verify --short HEAD~1) &&
142 head3=$(git rev-parse --verify --short HEAD~2) &&
143 head4=$(git rev-parse --verify --short HEAD~3)
146 test_expect_success
'left alignment formatting' '
147 git log --pretty="format:%<(40)%s" >actual &&
148 # complete the incomplete line at the end
150 qz_to_tab_space <<EOF >expected &&
156 test_cmp expected actual
159 test_expect_success
'left alignment formatting at the nth column' '
160 git log --pretty="format:%h %<|(40)%s" >actual &&
161 # complete the incomplete line at the end
163 qz_to_tab_space <<EOF >expected &&
167 $head4 $(commit_msg) Z
169 test_cmp expected actual
172 test_expect_success
'left alignment formatting with no padding' '
173 git log --pretty="format:%<(1)%s" >actual &&
174 # complete the incomplete line at the end
176 cat <<EOF >expected &&
182 test_cmp expected actual
185 test_expect_success
'left alignment formatting with trunc' '
186 git log --pretty="format:%<(10,trunc)%s" >actual &&
187 # complete the incomplete line at the end
189 qz_to_tab_space <<EOF >expected &&
195 test_cmp expected actual
198 test_expect_success
'left alignment formatting with ltrunc' '
199 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
200 # complete the incomplete line at the end
202 qz_to_tab_space <<EOF >expected &&
206 ..${sample_utf8_part}lich
208 test_cmp expected actual
211 test_expect_success
'left alignment formatting with mtrunc' '
212 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
213 # complete the incomplete line at the end
215 qz_to_tab_space <<EOF >expected &&
221 test_cmp expected actual
224 test_expect_success
'right alignment formatting' '
225 git log --pretty="format:%>(40)%s" >actual &&
226 # complete the incomplete line at the end
228 qz_to_tab_space <<EOF >expected &&
234 test_cmp expected actual
237 test_expect_success
'right alignment formatting at the nth column' '
238 git log --pretty="format:%h %>|(40)%s" >actual &&
239 # complete the incomplete line at the end
241 qz_to_tab_space <<EOF >expected &&
247 test_cmp expected actual
250 test_expect_success
'right alignment formatting with no padding' '
251 git log --pretty="format:%>(1)%s" >actual &&
252 # complete the incomplete line at the end
254 cat <<EOF >expected &&
260 test_cmp expected actual
263 test_expect_success
'center alignment formatting' '
264 git log --pretty="format:%><(40)%s" >actual &&
265 # complete the incomplete line at the end
267 qz_to_tab_space <<EOF >expected &&
273 test_cmp expected actual
276 test_expect_success
'center alignment formatting at the nth column' '
277 git log --pretty="format:%h %><|(40)%s" >actual &&
278 # complete the incomplete line at the end
280 qz_to_tab_space <<EOF >expected &&
284 $head4 $(commit_msg) Z
286 test_cmp expected actual
289 test_expect_success
'center alignment formatting with no padding' '
290 git log --pretty="format:%><(1)%s" >actual &&
291 # complete the incomplete line at the end
293 cat <<EOF >expected &&
299 test_cmp expected actual
302 # save HEAD's SHA-1 digest (with no abbreviations) to use it below
303 # as far as the next test amends HEAD
304 old_head1
=$
(git rev-parse
--verify HEAD~
0)
306 test_expect_success
'left/right alignment formatting with stealing' '
307 git commit --amend -m short --author "long long long <long@me.com>" &&
308 git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
309 # complete the incomplete line at the end
311 cat <<EOF >expected &&
317 test_cmp expected actual
320 # get new digests (with no abbreviations)
321 head1
=$
(git rev-parse
--verify HEAD~
0) &&
322 head2
=$
(git rev-parse
--verify HEAD~
1) &&
324 test_expect_success
'log decoration properly follows tag chain' '
325 git tag -a tag1 -m tag1 &&
326 git tag -a tag2 -m tag2 tag1 &&
328 git commit --amend -m shorter &&
329 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
330 cat <<EOF >expected &&
331 $head1 (tag: refs/tags/tag2)
332 $head2 (tag: refs/tags/message-one)
333 $old_head1 (tag: refs/tags/message-two)
335 sort actual >actual1 &&
336 test_cmp expected actual1