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 sample_utf8_part
=$
(printf "f\303\244ng")
13 # String "initial. initial" partly in German
14 # (translated with Google Translate),
15 # encoded in UTF-8, used as a commit log message below.
16 msg
="initial. an${sample_utf8_part}lich\n"
19 printf "$msg" |
iconv -f utf-8
-t "$1"
25 test_expect_success
'set up basic repos' '
30 git config i18n.commitEncoding iso8859-1 &&
31 # "git commit -m" would break MinGW, as Windows refuse to pass
32 # iso8859-1 encoded parameter to git.
33 commit_msg iso8859-1 | git commit -F - &&
36 git commit -m "add bar" &&
37 git config --unset i18n.commitEncoding
40 test_expect_success
'alias builtin format' '
41 git log --pretty=oneline >expected &&
42 git config pretty.test-alias oneline &&
43 git log --pretty=test-alias >actual &&
44 test_cmp expected actual
47 test_expect_success
'alias masking builtin format' '
48 git log --pretty=oneline >expected &&
49 git config pretty.oneline "%H" &&
50 git log --pretty=oneline >actual &&
51 test_cmp expected actual
54 test_expect_success
'alias user-defined format' '
55 git log --pretty="format:%h" >expected &&
56 git config pretty.test-alias "format:%h" &&
57 git log --pretty=test-alias >actual &&
58 test_cmp expected actual
61 test_expect_success
'alias user-defined tformat with %s (iso8859-1 encoding)' '
62 git config i18n.logOutputEncoding iso8859-1 &&
63 git log --oneline >expected-s &&
64 git log --pretty="tformat:%h %s" >actual-s &&
65 git config --unset i18n.logOutputEncoding &&
66 test_cmp expected-s actual-s
69 test_expect_success
'alias user-defined tformat with %s (utf-8 encoding)' '
70 git log --oneline >expected-s &&
71 git log --pretty="tformat:%h %s" >actual-s &&
72 test_cmp expected-s actual-s
75 test_expect_success
'alias user-defined tformat' '
76 git log --pretty="tformat:%h" >expected &&
77 git config pretty.test-alias "tformat:%h" &&
78 git log --pretty=test-alias >actual &&
79 test_cmp expected actual
82 test_expect_success
'alias non-existent format' '
83 git config pretty.test-alias format-that-will-never-exist &&
84 test_must_fail git log --pretty=test-alias
87 test_expect_success
'alias of an alias' '
88 git log --pretty="tformat:%h" >expected &&
89 git config pretty.test-foo "tformat:%h" &&
90 git config pretty.test-bar test-foo &&
91 git log --pretty=test-bar >actual && test_cmp expected actual
94 test_expect_success
'alias masking an alias' '
95 git log --pretty=format:"Two %H" >expected &&
96 git config pretty.duplicate "format:One %H" &&
97 git config --add pretty.duplicate "format:Two %H" &&
98 git log --pretty=duplicate >actual &&
99 test_cmp expected actual
102 test_expect_success
'alias loop' '
103 git config pretty.test-foo test-bar &&
104 git config pretty.test-bar test-foo &&
105 test_must_fail git log --pretty=test-foo
108 test_expect_success
'NUL separation' '
109 printf "add bar\0$(commit_msg)" >expected &&
110 git log -z --pretty="format:%s" >actual &&
111 test_cmp expected actual
114 test_expect_success
'NUL termination' '
115 printf "add bar\0$(commit_msg)\0" >expected &&
116 git log -z --pretty="tformat:%s" >actual &&
117 test_cmp expected actual
120 test_expect_success
'NUL separation with --stat' '
121 stat0_part=$(git diff --stat HEAD^ HEAD) &&
122 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
123 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
124 git log -z --stat --pretty="format:%s" >actual &&
125 test_i18ncmp expected actual
128 test_expect_failure
'NUL termination with --stat' '
129 stat0_part=$(git diff --stat HEAD^ HEAD) &&
130 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
131 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
132 git log -z --stat --pretty="tformat:%s" >actual &&
133 test_i18ncmp expected actual
136 test_expect_success
'setup more commits' '
137 test_commit "message one" one one message-one &&
138 test_commit "message two" two two message-two &&
139 head1=$(git rev-parse --verify --short HEAD~0) &&
140 head2=$(git rev-parse --verify --short HEAD~1) &&
141 head3=$(git rev-parse --verify --short HEAD~2) &&
142 head4=$(git rev-parse --verify --short HEAD~3)
145 test_expect_success
'left alignment formatting' '
146 git log --pretty="format:%<(40)%s" >actual &&
147 # complete the incomplete line at the end
149 qz_to_tab_space <<EOF >expected &&
155 test_cmp expected actual
158 test_expect_success
'left alignment formatting at the nth column' '
159 git log --pretty="format:%h %<|(40)%s" >actual &&
160 # complete the incomplete line at the end
162 qz_to_tab_space <<EOF >expected &&
166 $head4 $(commit_msg) Z
168 test_cmp expected actual
171 test_expect_success
'left alignment formatting with no padding' '
172 git log --pretty="format:%<(1)%s" >actual &&
173 # complete the incomplete line at the end
175 cat <<EOF >expected &&
181 test_cmp expected actual
184 test_expect_success
'left alignment formatting with trunc' '
185 git log --pretty="format:%<(10,trunc)%s" >actual &&
186 # complete the incomplete line at the end
188 qz_to_tab_space <<EOF >expected &&
194 test_cmp expected actual
197 test_expect_success
'left alignment formatting with ltrunc' '
198 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
199 # complete the incomplete line at the end
201 qz_to_tab_space <<EOF >expected &&
205 ..${sample_utf8_part}lich
207 test_cmp expected actual
210 test_expect_success
'left alignment formatting with mtrunc' '
211 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
212 # complete the incomplete line at the end
214 qz_to_tab_space <<EOF >expected &&
220 test_cmp expected actual
223 test_expect_success
'right alignment formatting' '
224 git log --pretty="format:%>(40)%s" >actual &&
225 # complete the incomplete line at the end
227 qz_to_tab_space <<EOF >expected &&
233 test_cmp expected actual
236 test_expect_success
'right alignment formatting at the nth column' '
237 git log --pretty="format:%h %>|(40)%s" >actual &&
238 # complete the incomplete line at the end
240 qz_to_tab_space <<EOF >expected &&
246 test_cmp expected actual
249 test_expect_success
'right alignment formatting with no padding' '
250 git log --pretty="format:%>(1)%s" >actual &&
251 # complete the incomplete line at the end
253 cat <<EOF >expected &&
259 test_cmp expected actual
262 test_expect_success
'center alignment formatting' '
263 git log --pretty="format:%><(40)%s" >actual &&
264 # complete the incomplete line at the end
266 qz_to_tab_space <<EOF >expected &&
272 test_cmp expected actual
275 test_expect_success
'center alignment formatting at the nth column' '
276 git log --pretty="format:%h %><|(40)%s" >actual &&
277 # complete the incomplete line at the end
279 qz_to_tab_space <<EOF >expected &&
283 $head4 $(commit_msg) Z
285 test_cmp expected actual
288 test_expect_success
'center alignment formatting with no padding' '
289 git log --pretty="format:%><(1)%s" >actual &&
290 # complete the incomplete line at the end
292 cat <<EOF >expected &&
298 test_cmp expected actual
301 test_expect_success
'left/right alignment formatting with stealing' '
302 git commit --amend -m short --author "long long long <long@me.com>" &&
303 git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
304 # complete the incomplete line at the end
306 cat <<EOF >expected &&
312 test_cmp expected actual
315 test_expect_success
'log decoration properly follows tag chain' '
316 git tag -a tag1 -m tag1 &&
317 git tag -a tag2 -m tag2 tag1 &&
319 git commit --amend -m shorter &&
320 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
321 cat <<EOF >expected &&
322 6a908c10688b2503073c39c9ba26322c73902bb5 (tag: refs/tags/tag2)
323 9f716384d92283fb915a4eee5073f030638e05f9 (tag: refs/tags/message-one)
324 b87e4cccdb77336ea79d89224737be7ea8e95367 (tag: refs/tags/message-two)
326 sort actual >actual1 &&
327 test_cmp expected actual1