builtin-commit: add --date option
[git/vmiklos.git] / t / t6006-rev-list-format.sh
blob571931588eda5799efbf2b0789abd10b8770a0a7
1 #!/bin/sh
3 test_description='git rev-list --pretty=format test'
5 . ./test-lib.sh
7 test_tick
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
14 test_format() {
15 cat >expect.$1
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 hash %H%n%h <<'EOF'
23 commit 131a310eb913d107dd3c09a65d1651175898735d
24 131a310eb913d107dd3c09a65d1651175898735d
25 131a310
26 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
27 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
28 86c75cf
29 EOF
31 test_format tree %T%n%t <<'EOF'
32 commit 131a310eb913d107dd3c09a65d1651175898735d
33 fe722612f26da5064c32ca3843aa154bdb0b08a0
34 fe72261
35 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
36 4d5fcadc293a348e88f777dc0920f11e7d71441c
37 4d5fcad
38 EOF
40 test_format parents %P%n%p <<'EOF'
41 commit 131a310eb913d107dd3c09a65d1651175898735d
42 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
43 86c75cf
44 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
47 EOF
49 # we don't test relative here
50 test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
51 commit 131a310eb913d107dd3c09a65d1651175898735d
52 A U Thor
53 author@example.com
54 Thu Apr 7 15:13:13 2005 -0700
55 Thu, 7 Apr 2005 15:13:13 -0700
56 1112911993
57 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
58 A U Thor
59 author@example.com
60 Thu Apr 7 15:13:13 2005 -0700
61 Thu, 7 Apr 2005 15:13:13 -0700
62 1112911993
63 EOF
65 test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
66 commit 131a310eb913d107dd3c09a65d1651175898735d
67 C O Mitter
68 committer@example.com
69 Thu Apr 7 15:13:13 2005 -0700
70 Thu, 7 Apr 2005 15:13:13 -0700
71 1112911993
72 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
73 C O Mitter
74 committer@example.com
75 Thu Apr 7 15:13:13 2005 -0700
76 Thu, 7 Apr 2005 15:13:13 -0700
77 1112911993
78 EOF
80 test_format encoding %e <<'EOF'
81 commit 131a310eb913d107dd3c09a65d1651175898735d
82 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
83 EOF
85 test_format subject %s <<'EOF'
86 commit 131a310eb913d107dd3c09a65d1651175898735d
87 changed foo
88 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
89 added foo
90 EOF
92 test_format body %b <<'EOF'
93 commit 131a310eb913d107dd3c09a65d1651175898735d
94 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
95 EOF
97 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
98 commit 131a310eb913d107dd3c09a65d1651175898735d
99 \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
100 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
101 \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
104 test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
105 commit 131a310eb913d107dd3c09a65d1651175898735d
106 \e[1;31;43mfoo\e[m
107 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
108 \e[1;31;43mfoo\e[m
111 cat >commit-msg <<'EOF'
112 Test printing of complex bodies
114 This commit message is much longer than the others,
115 and it will be encoded in iso8859-1. We should therefore
116 include an iso8859 character: ¡bueno!
118 test_expect_success 'setup complex body' '
119 git config i18n.commitencoding iso8859-1 &&
120 echo change2 >foo && git commit -a -F commit-msg
123 test_format complex-encoding %e <<'EOF'
124 commit f58db70b055c5718631e5c61528b28b12090cdea
125 iso8859-1
126 commit 131a310eb913d107dd3c09a65d1651175898735d
127 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
130 test_format complex-subject %s <<'EOF'
131 commit f58db70b055c5718631e5c61528b28b12090cdea
132 Test printing of complex bodies
133 commit 131a310eb913d107dd3c09a65d1651175898735d
134 changed foo
135 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
136 added foo
139 test_format complex-body %b <<'EOF'
140 commit f58db70b055c5718631e5c61528b28b12090cdea
141 This commit message is much longer than the others,
142 and it will be encoded in iso8859-1. We should therefore
143 include an iso8859 character: ¡bueno!
145 commit 131a310eb913d107dd3c09a65d1651175898735d
146 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
149 test_expect_success '%ad respects --date=' '
150 echo 2005-04-07 >expect.ad-short &&
151 git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
152 test_cmp expect.ad-short output.ad-short
155 test_expect_success 'empty email' '
156 test_tick &&
157 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
158 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
159 test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
160 echo "Eh? $A" >failure
161 false
165 test_expect_success 'del LF before empty (1)' '
166 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
167 test $(wc -l <actual) = 2
170 test_expect_success 'del LF before empty (2)' '
171 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
172 test $(wc -l <actual) = 6 &&
173 grep "^$" actual
176 test_expect_success 'add LF before non-empty (1)' '
177 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
178 test $(wc -l <actual) = 2
181 test_expect_success 'add LF before non-empty (2)' '
182 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
183 test $(wc -l <actual) = 6 &&
184 grep "^$" actual
187 test_expect_success '"%h %gD: %gs" is same as git-reflog' '
188 git reflog >expect &&
189 git log -g --format="%h %gD: %gs" >actual &&
190 test_cmp expect actual
193 test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
194 git reflog --date=raw >expect &&
195 git log -g --format="%h %gD: %gs" --date=raw >actual &&
196 test_cmp expect actual
199 test_expect_success '%gd shortens ref name' '
200 echo "master@{0}" >expect.gd-short &&
201 git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&
202 test_cmp expect.gd-short actual.gd-short
205 test_done