blob: 0dc915ea67b21d07d8e4dca44767906e05ad2278 [file] [log] [blame]
Jeff Kingfa21b602007-03-27 20:08:28 -04001#!/bin/sh
2
Junio C Hamano5be60072007-07-02 22:52:14 -07003test_description='git rev-list --pretty=format test'
Jeff Kingfa21b602007-03-27 20:08:28 -04004
5. ./test-lib.sh
6
7test_tick
8test_expect_success 'setup' '
Junio C Hamano5be60072007-07-02 22:52:14 -07009touch foo && git add foo && git-commit -m "added foo" &&
Jeff Kingfa21b602007-03-27 20:08:28 -040010 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" "
Junio C Hamano5be60072007-07-02 22:52:14 -070017git rev-list --pretty=format:$2 master >output.$1 &&
18git diff expect.$1 output.$1
Jeff Kingfa21b602007-03-27 20:08:28 -040019"
20}
21
22test_format hash %H%n%h <<'EOF'
23commit 131a310eb913d107dd3c09a65d1651175898735d
24131a310eb913d107dd3c09a65d1651175898735d
25131a310
26commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
2786c75cfd708a0e5868dc876ed5b8bb66c80b4873
2886c75cf
29EOF
30
31test_format tree %T%n%t <<'EOF'
32commit 131a310eb913d107dd3c09a65d1651175898735d
33fe722612f26da5064c32ca3843aa154bdb0b08a0
34fe72261
35commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
364d5fcadc293a348e88f777dc0920f11e7d71441c
374d5fcad
38EOF
39
40test_format parents %P%n%p <<'EOF'
41commit 131a310eb913d107dd3c09a65d1651175898735d
Junio C Hamano542e1652007-03-28 13:33:37 -07004286c75cfd708a0e5868dc876ed5b8bb66c80b4873
4386c75cf
Jeff Kingfa21b602007-03-27 20:08:28 -040044commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
Junio C Hamano542e1652007-03-28 13:33:37 -070045
46
Jeff Kingfa21b602007-03-27 20:08:28 -040047EOF
48
49# we don't test relative here
50test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
51commit 131a310eb913d107dd3c09a65d1651175898735d
52A U Thor
53author@example.com
54Thu Apr 7 15:13:13 2005 -0700
55Thu, 7 Apr 2005 15:13:13 -0700
561112911993
57commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
58A U Thor
59author@example.com
60Thu Apr 7 15:13:13 2005 -0700
61Thu, 7 Apr 2005 15:13:13 -0700
621112911993
63EOF
64
65test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
66commit 131a310eb913d107dd3c09a65d1651175898735d
67C O Mitter
68committer@example.com
69Thu Apr 7 15:13:13 2005 -0700
70Thu, 7 Apr 2005 15:13:13 -0700
711112911993
72commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
73C O Mitter
74committer@example.com
75Thu Apr 7 15:13:13 2005 -0700
76Thu, 7 Apr 2005 15:13:13 -0700
771112911993
78EOF
79
80test_format encoding %e <<'EOF'
81commit 131a310eb913d107dd3c09a65d1651175898735d
Jeff Kingfa21b602007-03-27 20:08:28 -040082commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
Jeff Kingfa21b602007-03-27 20:08:28 -040083EOF
84
85test_format subject %s <<'EOF'
86commit 131a310eb913d107dd3c09a65d1651175898735d
87changed foo
88commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
89added foo
90EOF
91
92test_format body %b <<'EOF'
93commit 131a310eb913d107dd3c09a65d1651175898735d
Jeff Kingfa21b602007-03-27 20:08:28 -040094commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
Jeff Kingfa21b602007-03-27 20:08:28 -040095EOF
96
97test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
98commit 131a310eb913d107dd3c09a65d1651175898735d
99foobarbazxyzzy
100commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
101foobarbazxyzzy
102EOF
103
Jeff King03bcaac2007-03-28 17:08:36 -0400104cat >commit-msg <<'EOF'
105Test printing of complex bodies
106
107This commit message is much longer than the others,
108and it will be encoded in iso8859-1. We should therefore
109include an iso8859 character: ¡bueno!
110EOF
111test_expect_success 'setup complex body' '
Junio C Hamano5be60072007-07-02 22:52:14 -0700112git config i18n.commitencoding iso8859-1 &&
Jeff King03bcaac2007-03-28 17:08:36 -0400113 echo change2 >foo && git-commit -a -F commit-msg
114'
115
116test_format complex-encoding %e <<'EOF'
117commit f58db70b055c5718631e5c61528b28b12090cdea
118iso8859-1
119commit 131a310eb913d107dd3c09a65d1651175898735d
Jeff King03bcaac2007-03-28 17:08:36 -0400120commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
Jeff King03bcaac2007-03-28 17:08:36 -0400121EOF
122
123test_format complex-subject %s <<'EOF'
124commit f58db70b055c5718631e5c61528b28b12090cdea
125Test printing of complex bodies
126commit 131a310eb913d107dd3c09a65d1651175898735d
127changed foo
128commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
129added foo
130EOF
131
132test_format complex-body %b <<'EOF'
133commit f58db70b055c5718631e5c61528b28b12090cdea
134This commit message is much longer than the others,
135and it will be encoded in iso8859-1. We should therefore
136include an iso8859 character: ¡bueno!
137
138commit 131a310eb913d107dd3c09a65d1651175898735d
Jeff King03bcaac2007-03-28 17:08:36 -0400139commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
Jeff King03bcaac2007-03-28 17:08:36 -0400140EOF
141
Junio C Hamanof7ab5c72008-01-06 04:21:07 -0800142test_expect_success 'empty email' '
143 test_tick &&
144 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
145 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
146 test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
147 echo "Eh? $A" >failure
148 false
149 }
150'
151
Jeff Kingfa21b602007-03-27 20:08:28 -0400152test_done