3 test_description='git rev-list --pretty=format test'
8 test_expect_success 'setup' '
9 touch foo && git add foo && git commit -m "added foo" &&
10 echo changed >foo && git commit -a -m "changed foo"
13 # usage: test_format name format_string <expected_output
16 test_expect_success "format $1" "
17 git rev-list --pretty=format:'$2' master >output.$1 &&
18 test_cmp expect.$1 output.$1
22 test_format percent %%h <<'EOF'
23 commit 131a310eb913d107dd3c09a65d1651175898735d
25 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
29 test_format hash %H%n%h <<'EOF'
30 commit 131a310eb913d107dd3c09a65d1651175898735d
31 131a310eb913d107dd3c09a65d1651175898735d
33 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
34 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
38 test_format tree %T%n%t <<'EOF'
39 commit 131a310eb913d107dd3c09a65d1651175898735d
40 fe722612f26da5064c32ca3843aa154bdb0b08a0
42 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
43 4d5fcadc293a348e88f777dc0920f11e7d71441c
47 test_format parents %P%n%p <<'EOF'
48 commit 131a310eb913d107dd3c09a65d1651175898735d
49 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
51 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
56 # we don't test relative here
57 test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
58 commit 131a310eb913d107dd3c09a65d1651175898735d
61 Thu Apr 7 15:13:13 2005 -0700
62 Thu, 7 Apr 2005 15:13:13 -0700
64 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
67 Thu Apr 7 15:13:13 2005 -0700
68 Thu, 7 Apr 2005 15:13:13 -0700
72 test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
73 commit 131a310eb913d107dd3c09a65d1651175898735d
76 Thu Apr 7 15:13:13 2005 -0700
77 Thu, 7 Apr 2005 15:13:13 -0700
79 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
82 Thu Apr 7 15:13:13 2005 -0700
83 Thu, 7 Apr 2005 15:13:13 -0700
87 test_format encoding %e <<'EOF'
88 commit 131a310eb913d107dd3c09a65d1651175898735d
89 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
92 test_format subject %s <<'EOF'
93 commit 131a310eb913d107dd3c09a65d1651175898735d
95 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
99 test_format body %b <<'EOF'
100 commit 131a310eb913d107dd3c09a65d1651175898735d
101 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
104 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
105 commit 131a310eb913d107dd3c09a65d1651175898735d
106 \e[31mfoo
\e[32mbar
\e[34mbaz
\e[mxyzzy
107 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
108 \e[31mfoo
\e[32mbar
\e[34mbaz
\e[mxyzzy
111 test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
112 commit 131a310eb913d107dd3c09a65d1651175898735d
114 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
118 cat >commit-msg <<'EOF'
119 Test printing of complex bodies
121 This commit message is much longer than the others,
122 and it will be encoded in iso8859-1. We should therefore
123 include an iso8859 character: ¡bueno!
125 test_expect_success 'setup complex body' '
126 git config i18n.commitencoding iso8859-1 &&
127 echo change2 >foo && git commit -a -F commit-msg
130 test_format complex-encoding %e <<'EOF'
131 commit f58db70b055c5718631e5c61528b28b12090cdea
133 commit 131a310eb913d107dd3c09a65d1651175898735d
134 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
137 test_format complex-subject %s <<'EOF'
138 commit f58db70b055c5718631e5c61528b28b12090cdea
139 Test printing of complex bodies
140 commit 131a310eb913d107dd3c09a65d1651175898735d
142 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
146 test_format complex-body %b <<'EOF'
147 commit f58db70b055c5718631e5c61528b28b12090cdea
148 This commit message is much longer than the others,
149 and it will be encoded in iso8859-1. We should therefore
150 include an iso8859 character: ¡bueno!
152 commit 131a310eb913d107dd3c09a65d1651175898735d
153 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
156 test_expect_success '%ad respects --date=' '
157 echo 2005-04-07 >expect.ad-short &&
158 git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
159 test_cmp expect.ad-short output.ad-short
162 test_expect_success 'empty email' '
164 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
165 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
166 test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
167 echo "Eh? $A" >failure
172 test_expect_success 'del LF before empty (1)' '
173 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
174 test $(wc -l <actual) = 2
177 test_expect_success 'del LF before empty (2)' '
178 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
179 test $(wc -l <actual) = 6 &&
183 test_expect_success 'add LF before non-empty (1)' '
184 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
185 test $(wc -l <actual) = 2
188 test_expect_success 'add LF before non-empty (2)' '
189 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
190 test $(wc -l <actual) = 6 &&
194 test_expect_success '--abbrev' '
195 echo SHORT SHORT SHORT >expect2 &&
196 echo LONG LONG LONG >expect3 &&
197 git log -1 --format="%h %h %h" HEAD >actual1 &&
198 git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 &&
199 git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 &&
200 sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 &&
201 sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 &&
202 test_cmp expect2 fuzzy2 &&
203 test_cmp expect3 fuzzy3 &&
204 ! test_cmp actual1 actual2
207 test_expect_success '%H is not affected by --abbrev-commit' '
208 git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual &&
209 len=$(wc -c <actual) &&
213 test_expect_success '%h is not affected by --abbrev-commit' '
214 git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual &&
215 len=$(wc -c <actual) &&
219 test_expect_success '"%h %gD: %gs" is same as git-reflog' '
220 git reflog >expect &&
221 git log -g --format="%h %gD: %gs" >actual &&
222 test_cmp expect actual
225 test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
226 git reflog --date=raw >expect &&
227 git log -g --format="%h %gD: %gs" --date=raw >actual &&
228 test_cmp expect actual
231 test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' '
232 git reflog --abbrev=13 --date=raw >expect &&
233 git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual &&
234 test_cmp expect actual
237 test_expect_success '%gd shortens ref name' '
238 echo "master@{0}" >expect.gd-short &&
239 git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&
240 test_cmp expect.gd-short actual.gd-short
243 test_expect_success 'oneline with empty message' '
244 git commit -m "dummy" --allow-empty &&
245 git commit -m "dummy" --allow-empty &&
246 git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. &&
247 git rev-list --oneline HEAD >test.txt &&
248 test $(git rev-list --oneline HEAD | wc -l) -eq 5 &&
249 test $(git rev-list --oneline --graph HEAD | wc -l) -eq 5