1#!/bin/sh
2
3test_description='git rev-list --pretty=format test'
4
5. ./test-lib.sh
6
7test_tick
8test_expect_success 'setup' '
9touch foo && git add foo && git commit -m "added foo" &&
10 echo changed >foo && git commit -a -m "changed foo"
11'
12
13# usage: test_format name format_string <expected_output
14test_format() {
15 cat >expect.$1
16 test_expect_success "format $1" "
17git rev-list --pretty=format:'$2' master >output.$1 &&
18test_cmp expect.$1 output.$1
19"
20}
21
22test_format percent %%h <<'EOF'
23commit 131a310eb913d107dd3c09a65d1651175898735d
24%h
25commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
26%h
27EOF
28
29test_format hash %H%n%h <<'EOF'
30commit 131a310eb913d107dd3c09a65d1651175898735d
31131a310eb913d107dd3c09a65d1651175898735d
32131a310
33commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
3486c75cfd708a0e5868dc876ed5b8bb66c80b4873
3586c75cf
36EOF
37
38test_format tree %T%n%t <<'EOF'
39commit 131a310eb913d107dd3c09a65d1651175898735d
40fe722612f26da5064c32ca3843aa154bdb0b08a0
41fe72261
42commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
434d5fcadc293a348e88f777dc0920f11e7d71441c
444d5fcad
45EOF
46
47test_format parents %P%n%p <<'EOF'
48commit 131a310eb913d107dd3c09a65d1651175898735d
4986c75cfd708a0e5868dc876ed5b8bb66c80b4873
5086c75cf
51commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
52
53
54EOF
55
56# we don't test relative here
57test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
58commit 131a310eb913d107dd3c09a65d1651175898735d
59A U Thor
60author@example.com
61Thu Apr 7 15:13:13 2005 -0700
62Thu, 7 Apr 2005 15:13:13 -0700
631112911993
64commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
65A U Thor
66author@example.com
67Thu Apr 7 15:13:13 2005 -0700
68Thu, 7 Apr 2005 15:13:13 -0700
691112911993
70EOF
71
72test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
73commit 131a310eb913d107dd3c09a65d1651175898735d
74C O Mitter
75committer@example.com
76Thu Apr 7 15:13:13 2005 -0700
77Thu, 7 Apr 2005 15:13:13 -0700
781112911993
79commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
80C O Mitter
81committer@example.com
82Thu Apr 7 15:13:13 2005 -0700
83Thu, 7 Apr 2005 15:13:13 -0700
841112911993
85EOF
86
87test_format encoding %e <<'EOF'
88commit 131a310eb913d107dd3c09a65d1651175898735d
89commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
90EOF
91
92test_format subject %s <<'EOF'
93commit 131a310eb913d107dd3c09a65d1651175898735d
94changed foo
95commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
96added foo
97EOF
98
99test_format body %b <<'EOF'
100commit 131a310eb913d107dd3c09a65d1651175898735d
101commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
102EOF
103
104test_format raw-body %B <<'EOF'
105commit 131a310eb913d107dd3c09a65d1651175898735d
106changed foo
107
108commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
109added foo
110
111EOF
112
113test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
114commit 131a310eb913d107dd3c09a65d1651175898735d
115\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
116commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
117\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
118EOF
119
120test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
121commit 131a310eb913d107dd3c09a65d1651175898735d
122\e[1;31;43mfoo\e[m
123commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
124\e[1;31;43mfoo\e[m
125EOF
126
127cat >commit-msg <<'EOF'
128Test printing of complex bodies
129
130This commit message is much longer than the others,
131and it will be encoded in iso8859-1. We should therefore
132include an iso8859 character: ¡bueno!
133EOF
134test_expect_success 'setup complex body' '
135git config i18n.commitencoding iso8859-1 &&
136 echo change2 >foo && git commit -a -F commit-msg
137'
138
139test_format complex-encoding %e <<'EOF'
140commit f58db70b055c5718631e5c61528b28b12090cdea
141iso8859-1
142commit 131a310eb913d107dd3c09a65d1651175898735d
143commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
144EOF
145
146test_format complex-subject %s <<'EOF'
147commit f58db70b055c5718631e5c61528b28b12090cdea
148Test printing of complex bodies
149commit 131a310eb913d107dd3c09a65d1651175898735d
150changed foo
151commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
152added foo
153EOF
154
155test_format complex-body %b <<'EOF'
156commit f58db70b055c5718631e5c61528b28b12090cdea
157This commit message is much longer than the others,
158and it will be encoded in iso8859-1. We should therefore
159include an iso8859 character: ¡bueno!
160
161commit 131a310eb913d107dd3c09a65d1651175898735d
162commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
163EOF
164
165test_expect_success '%ad respects --date=' '
166 echo 2005-04-07 >expect.ad-short &&
167 git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
168 test_cmp expect.ad-short output.ad-short
169'
170
171test_expect_success 'empty email' '
172 test_tick &&
173 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
174 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
175 test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
176 echo "Eh? $A" >failure
177 false
178 }
179'
180
181test_expect_success 'del LF before empty (1)' '
182 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
183 test $(wc -l <actual) = 2
184'
185
186test_expect_success 'del LF before empty (2)' '
187 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
188 test $(wc -l <actual) = 6 &&
189 grep "^$" actual
190'
191
192test_expect_success 'add LF before non-empty (1)' '
193 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
194 test $(wc -l <actual) = 2
195'
196
197test_expect_success 'add LF before non-empty (2)' '
198 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
199 test $(wc -l <actual) = 6 &&
200 grep "^$" actual
201'
202
203test_expect_success '"%h %gD: %gs" is same as git-reflog' '
204 git reflog >expect &&
205 git log -g --format="%h %gD: %gs" >actual &&
206 test_cmp expect actual
207'
208
209test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
210 git reflog --date=raw >expect &&
211 git log -g --format="%h %gD: %gs" --date=raw >actual &&
212 test_cmp expect actual
213'
214
215test_expect_success '%gd shortens ref name' '
216 echo "master@{0}" >expect.gd-short &&
217 git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&
218 test_cmp expect.gd-short actual.gd-short
219'
220
221test_expect_success 'oneline with empty message' '
222 git commit -m "dummy" --allow-empty &&
223 git commit -m "dummy" --allow-empty &&
224 git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. &&
225 git rev-list --oneline HEAD >test.txt &&
226 test $(git rev-list --oneline HEAD | wc -l) -eq 5 &&
227 test $(git rev-list --oneline --graph HEAD | wc -l) -eq 5
228'
229
230test_done