3 # Copyright (c) 2010, Will Palmer
6 test_description
='Test pretty formats'
9 test_expect_success
'set up basic repos' '
14 git commit -m initial &&
17 git commit -m "add bar"
20 test_expect_success
'alias builtin format' '
21 git log --pretty=oneline >expected &&
22 git config pretty.test-alias oneline &&
23 git log --pretty=test-alias >actual &&
24 test_cmp expected actual
27 test_expect_success
'alias masking builtin format' '
28 git log --pretty=oneline >expected &&
29 git config pretty.oneline "%H" &&
30 git log --pretty=oneline >actual &&
31 test_cmp expected actual
34 test_expect_success
'alias user-defined format' '
35 git log --pretty="format:%h" >expected &&
36 git config pretty.test-alias "format:%h" &&
37 git log --pretty=test-alias >actual &&
38 test_cmp expected actual
41 test_expect_success
'alias user-defined tformat' '
42 git log --pretty="tformat:%h" >expected &&
43 git config pretty.test-alias "tformat:%h" &&
44 git log --pretty=test-alias >actual &&
45 test_cmp expected actual
48 test_expect_success
'alias non-existent format' '
49 git config pretty.test-alias format-that-will-never-exist &&
50 test_must_fail git log --pretty=test-alias
53 test_expect_success
'alias of an alias' '
54 git log --pretty="tformat:%h" >expected &&
55 git config pretty.test-foo "tformat:%h" &&
56 git config pretty.test-bar test-foo &&
57 git log --pretty=test-bar >actual && test_cmp expected actual
60 test_expect_success
'alias masking an alias' '
61 git log --pretty=format:"Two %H" >expected &&
62 git config pretty.duplicate "format:One %H" &&
63 git config --add pretty.duplicate "format:Two %H" &&
64 git log --pretty=duplicate >actual &&
65 test_cmp expected actual
68 test_expect_success
'alias loop' '
69 git config pretty.test-foo test-bar &&
70 git config pretty.test-bar test-foo &&
71 test_must_fail git log --pretty=test-foo
74 test_expect_success
'NUL separation' '
75 printf "add bar\0initial" >expected &&
76 git log -z --pretty="format:%s" >actual &&
77 test_cmp expected actual
80 test_expect_success
'NUL termination' '
81 printf "add bar\0initial\0" >expected &&
82 git log -z --pretty="tformat:%s" >actual &&
83 test_cmp expected actual
86 test_expect_success
'NUL separation with --stat' '
87 stat0_part=$(git diff --stat HEAD^ HEAD) &&
88 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
89 printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n" >expected &&
90 git log -z --stat --pretty="format:%s" >actual &&
91 test_i18ncmp expected actual
94 test_expect_failure
'NUL termination with --stat' '
95 stat0_part=$(git diff --stat HEAD^ HEAD) &&
96 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
97 printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n\0" >expected &&
98 git log -z --stat --pretty="tformat:%s" >actual &&
99 test_i18ncmp expected actual
102 test_expect_success
'setup more commits' '
103 test_commit "message one" one one message-one &&
104 test_commit "message two" two two message-two &&
105 head1=$(git rev-parse --verify --short HEAD~0) &&
106 head2=$(git rev-parse --verify --short HEAD~1) &&
107 head3=$(git rev-parse --verify --short HEAD~2) &&
108 head4=$(git rev-parse --verify --short HEAD~3)
111 test_expect_success
'left alignment formatting' '
112 git log --pretty="format:%<(40)%s" >actual &&
113 # complete the incomplete line at the end
115 qz_to_tab_space <<\EOF >expected &&
121 test_cmp expected actual
124 test_expect_success
'left alignment formatting at the nth column' "
125 git log --pretty='format:%h %<|(40)%s' >actual &&
126 # complete the incomplete line at the end
128 qz_to_tab_space <<\EOF >expected &&
134 test_cmp expected actual
137 test_expect_success
'left alignment formatting with no padding' '
138 git log --pretty="format:%<(1)%s" >actual &&
139 # complete the incomplete line at the end
141 cat <<\EOF >expected &&
147 test_cmp expected actual
150 test_expect_success
'left alignment formatting with trunc' '
151 git log --pretty="format:%<(10,trunc)%s" >actual &&
152 # complete the incomplete line at the end
154 qz_to_tab_space <<\EOF >expected &&
160 test_cmp expected actual
163 test_expect_success
'left alignment formatting with ltrunc' '
164 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
165 # complete the incomplete line at the end
167 qz_to_tab_space <<\EOF >expected &&
173 test_cmp expected actual
176 test_expect_success
'left alignment formatting with mtrunc' '
177 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
178 # complete the incomplete line at the end
180 qz_to_tab_space <<\EOF >expected &&
186 test_cmp expected actual
189 test_expect_success
'right alignment formatting' '
190 git log --pretty="format:%>(40)%s" >actual &&
191 # complete the incomplete line at the end
193 qz_to_tab_space <<\EOF >expected &&
199 test_cmp expected actual
202 test_expect_success
'right alignment formatting at the nth column' "
203 git log --pretty='format:%h %>|(40)%s' >actual &&
204 # complete the incomplete line at the end
206 qz_to_tab_space <<\EOF >expected &&
212 test_cmp expected actual
215 test_expect_success
'right alignment formatting with no padding' '
216 git log --pretty="format:%>(1)%s" >actual &&
217 # complete the incomplete line at the end
219 cat <<\EOF >expected &&
225 test_cmp expected actual
228 test_expect_success
'center alignment formatting' '
229 git log --pretty="format:%><(40)%s" >actual &&
230 # complete the incomplete line at the end
232 qz_to_tab_space <<\EOF >expected &&
238 test_cmp expected actual
241 test_expect_success
'center alignment formatting at the nth column' "
242 git log --pretty='format:%h %><|(40)%s' >actual &&
243 # complete the incomplete line at the end
245 qz_to_tab_space <<\EOF >expected &&
251 test_cmp expected actual
254 test_expect_success
'center alignment formatting with no padding' '
255 git log --pretty="format:%><(1)%s" >actual &&
256 # complete the incomplete line at the end
258 cat <<\EOF >expected &&
264 test_cmp expected actual
267 test_expect_success
'left/right alignment formatting with stealing' '
268 git commit --amend -m short --author "long long long <long@me.com>" &&
269 git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
270 # complete the incomplete line at the end
272 cat <<\EOF >expected &&
278 test_cmp expected actual