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 "$(commit_msg iso8859-1)" &&
34 git commit -m "add bar" &&
35 git config --unset i18n.commitEncoding
38 test_expect_success 'alias builtin format' '
39 git log --pretty=oneline >expected &&
40 git config pretty.test-alias oneline &&
41 git log --pretty=test-alias >actual &&
42 test_cmp expected actual
45 test_expect_success 'alias masking builtin format' '
46 git log --pretty=oneline >expected &&
47 git config pretty.oneline "%H" &&
48 git log --pretty=oneline >actual &&
49 test_cmp expected actual
52 test_expect_success 'alias user-defined format' '
53 git log --pretty="format:%h" >expected &&
54 git config pretty.test-alias "format:%h" &&
55 git log --pretty=test-alias >actual &&
56 test_cmp expected actual
59 test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
60 git config i18n.logOutputEncoding iso8859-1 &&
61 git log --oneline >expected-s &&
62 git log --pretty="tformat:%h %s" >actual-s &&
63 git config --unset i18n.logOutputEncoding &&
64 test_cmp expected-s actual-s
67 test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
68 git log --oneline >expected-s &&
69 git log --pretty="tformat:%h %s" >actual-s &&
70 test_cmp expected-s actual-s
73 test_expect_success 'alias user-defined tformat' '
74 git log --pretty="tformat:%h" >expected &&
75 git config pretty.test-alias "tformat:%h" &&
76 git log --pretty=test-alias >actual &&
77 test_cmp expected actual
80 test_expect_success 'alias non-existent format' '
81 git config pretty.test-alias format-that-will-never-exist &&
82 test_must_fail git log --pretty=test-alias
85 test_expect_success 'alias of an alias' '
86 git log --pretty="tformat:%h" >expected &&
87 git config pretty.test-foo "tformat:%h" &&
88 git config pretty.test-bar test-foo &&
89 git log --pretty=test-bar >actual && test_cmp expected actual
92 test_expect_success 'alias masking an alias' '
93 git log --pretty=format:"Two %H" >expected &&
94 git config pretty.duplicate "format:One %H" &&
95 git config --add pretty.duplicate "format:Two %H" &&
96 git log --pretty=duplicate >actual &&
97 test_cmp expected actual
100 test_expect_success 'alias loop' '
101 git config pretty.test-foo test-bar &&
102 git config pretty.test-bar test-foo &&
103 test_must_fail git log --pretty=test-foo
106 test_expect_success 'NUL separation' '
107 printf "add bar\0$(commit_msg)" >expected &&
108 git log -z --pretty="format:%s" >actual &&
109 test_cmp expected actual
112 test_expect_success 'NUL termination' '
113 printf "add bar\0$(commit_msg)\0" >expected &&
114 git log -z --pretty="tformat:%s" >actual &&
115 test_cmp expected actual
118 test_expect_success 'NUL separation with --stat' '
119 stat0_part=$(git diff --stat HEAD^ HEAD) &&
120 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
121 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
122 git log -z --stat --pretty="format:%s" >actual &&
123 test_i18ncmp expected actual
126 test_expect_failure 'NUL termination with --stat' '
127 stat0_part=$(git diff --stat HEAD^ HEAD) &&
128 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
129 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
130 git log -z --stat --pretty="tformat:%s" >actual &&
131 test_i18ncmp expected actual
134 test_expect_success 'setup more commits' '
135 test_commit "message one" one one message-one &&
136 test_commit "message two" two two message-two &&
137 head1=$(git rev-parse --verify --short HEAD~0) &&
138 head2=$(git rev-parse --verify --short HEAD~1) &&
139 head3=$(git rev-parse --verify --short HEAD~2) &&
140 head4=$(git rev-parse --verify --short HEAD~3)
143 test_expect_success 'left alignment formatting' '
144 git log --pretty="format:%<(40)%s" >actual &&
145 # complete the incomplete line at the end
147 qz_to_tab_space <<EOF >expected &&
153 test_cmp expected actual
156 test_expect_success 'left alignment formatting at the nth column' '
157 git log --pretty="format:%h %<|(40)%s" >actual &&
158 # complete the incomplete line at the end
160 qz_to_tab_space <<EOF >expected &&
164 $head4 $(commit_msg) Z
166 test_cmp expected actual
169 test_expect_success 'left alignment formatting with no padding' '
170 git log --pretty="format:%<(1)%s" >actual &&
171 # complete the incomplete line at the end
173 cat <<EOF >expected &&
179 test_cmp expected actual
182 test_expect_success 'left alignment formatting with trunc' '
183 git log --pretty="format:%<(10,trunc)%s" >actual &&
184 # complete the incomplete line at the end
186 qz_to_tab_space <<EOF >expected &&
192 test_cmp expected actual
195 test_expect_success 'left alignment formatting with ltrunc' '
196 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
197 # complete the incomplete line at the end
199 qz_to_tab_space <<EOF >expected &&
203 ..${sample_utf8_part}lich
205 test_cmp expected actual
208 test_expect_success 'left alignment formatting with mtrunc' '
209 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
210 # complete the incomplete line at the end
212 qz_to_tab_space <<EOF >expected &&
218 test_cmp expected actual
221 test_expect_success 'right alignment formatting' '
222 git log --pretty="format:%>(40)%s" >actual &&
223 # complete the incomplete line at the end
225 qz_to_tab_space <<EOF >expected &&
231 test_cmp expected actual
234 test_expect_success 'right alignment formatting at the nth column' '
235 git log --pretty="format:%h %>|(40)%s" >actual &&
236 # complete the incomplete line at the end
238 qz_to_tab_space <<EOF >expected &&
244 test_cmp expected actual
247 test_expect_success 'right alignment formatting with no padding' '
248 git log --pretty="format:%>(1)%s" >actual &&
249 # complete the incomplete line at the end
251 cat <<EOF >expected &&
257 test_cmp expected actual
260 test_expect_success 'center alignment formatting' '
261 git log --pretty="format:%><(40)%s" >actual &&
262 # complete the incomplete line at the end
264 qz_to_tab_space <<EOF >expected &&
270 test_cmp expected actual
273 test_expect_success 'center alignment formatting at the nth column' '
274 git log --pretty="format:%h %><|(40)%s" >actual &&
275 # complete the incomplete line at the end
277 qz_to_tab_space <<EOF >expected &&
281 $head4 $(commit_msg) Z
283 test_cmp expected actual
286 test_expect_success 'center alignment formatting with no padding' '
287 git log --pretty="format:%><(1)%s" >actual &&
288 # complete the incomplete line at the end
290 cat <<EOF >expected &&
296 test_cmp expected actual
299 test_expect_success 'left/right alignment formatting with stealing' '
300 git commit --amend -m short --author "long long long <long@me.com>" &&
301 git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
302 # complete the incomplete line at the end
304 cat <<EOF >expected &&
310 test_cmp expected actual
313 test_expect_success 'log decoration properly follows tag chain' '
314 git tag -a tag1 -m tag1 &&
315 git tag -a tag2 -m tag2 tag1 &&
317 git commit --amend -m shorter &&
318 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
319 cat <<EOF >expected &&
320 6a908c10688b2503073c39c9ba26322c73902bb5 (tag: refs/tags/tag2)
321 9f716384d92283fb915a4eee5073f030638e05f9 (tag: refs/tags/message-one)
322 b87e4cccdb77336ea79d89224737be7ea8e95367 (tag: refs/tags/message-two)
324 sort actual >actual1 &&
325 test_cmp expected actual1