]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6300-for-each-ref.sh
Merge branch 'jc/maint-log-grep'
[thirdparty/git.git] / t / t6300-for-each-ref.sh
CommitLineData
96b2d4fa
AP
1#!/bin/sh
2#
3# Copyright (c) 2007 Andy Parkins
4#
5
6test_description='for-each-ref test'
7
8. ./test-lib.sh
9
10# Mon Jul 3 15:18:43 2006 +0000
11datestamp=1151939923
12setdate_and_increment () {
13 GIT_COMMITTER_DATE="$datestamp +0200"
14 datestamp=$(expr "$datestamp" + 1)
15 GIT_AUTHOR_DATE="$datestamp +0200"
16 datestamp=$(expr "$datestamp" + 1)
17 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
18}
19
20test_expect_success 'Create sample commit with known timestamp' '
21 setdate_and_increment &&
22 echo "Using $datestamp" > one &&
23 git add one &&
24 git commit -m "Initial" &&
25 setdate_and_increment &&
26 git tag -a -m "Tagging at $datestamp" testtag
27'
28
d2bf48d2
JK
29test_atom() {
30 case "$1" in
31 head) ref=refs/heads/master ;;
32 tag) ref=refs/tags/testtag ;;
33 esac
34 printf '%s\n' "$3" >expected
35 test_expect_${4:-success} "basic atom: $1 $2" "
36 git for-each-ref --format='%($2)' $ref >actual &&
37 test_cmp expected actual
38 "
39}
40
41test_atom head refname refs/heads/master
42test_atom head objecttype commit
43test_atom head objectsize 171
44test_atom head objectname 67a36f10722846e891fbada1ba48ed035de75581
45test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f
46test_atom head parent ''
47test_atom head numparent 0
48test_atom head object ''
49test_atom head type ''
50test_atom head author 'A U Thor <author@example.com> 1151939924 +0200'
51test_atom head authorname 'A U Thor'
52test_atom head authoremail '<author@example.com>'
53test_atom head authordate 'Mon Jul 3 17:18:44 2006 +0200'
54test_atom head committer 'C O Mitter <committer@example.com> 1151939923 +0200'
55test_atom head committername 'C O Mitter'
56test_atom head committeremail '<committer@example.com>'
57test_atom head committerdate 'Mon Jul 3 17:18:43 2006 +0200'
58test_atom head tag ''
59test_atom head tagger ''
60test_atom head taggername ''
61test_atom head taggeremail ''
62test_atom head taggerdate ''
63test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200'
64test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200'
65test_atom head subject 'Initial'
66test_atom head body ''
67test_atom head contents 'Initial
68'
69
70test_atom tag refname refs/tags/testtag
71test_atom tag objecttype tag
72test_atom tag objectsize 154
73test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322
74test_atom tag tree ''
75test_atom tag parent ''
76test_atom tag numparent ''
77test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
78test_atom tag type 'commit'
79test_atom tag author ''
80test_atom tag authorname ''
81test_atom tag authoremail ''
82test_atom tag authordate ''
83test_atom tag committer ''
84test_atom tag committername ''
85test_atom tag committeremail ''
86test_atom tag committerdate ''
87test_atom tag tag 'testtag'
88test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200'
89test_atom tag taggername 'C O Mitter'
90test_atom tag taggeremail '<committer@example.com>'
91test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200'
92test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200'
93test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200'
94test_atom tag subject 'Tagging at 1151939927'
95test_atom tag body ''
96test_atom tag contents 'Tagging at 1151939927
96b2d4fa
AP
97'
98
41ac414e 99test_expect_success 'Check invalid atoms names are errors' '
3604e7c5 100 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
96b2d4fa
AP
101'
102
103test_expect_success 'Check format specifiers are ignored in naming date atoms' '
3604e7c5
NS
104 git for-each-ref --format="%(authordate)" refs/heads &&
105 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
106 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
107 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
96b2d4fa
AP
108'
109
110test_expect_success 'Check valid format specifiers for date fields' '
3604e7c5
NS
111 git for-each-ref --format="%(authordate:default)" refs/heads &&
112 git for-each-ref --format="%(authordate:relative)" refs/heads &&
113 git for-each-ref --format="%(authordate:short)" refs/heads &&
114 git for-each-ref --format="%(authordate:local)" refs/heads &&
115 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
116 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
96b2d4fa
AP
117'
118
41ac414e 119test_expect_success 'Check invalid format specifiers are errors' '
3604e7c5 120 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
96b2d4fa
AP
121'
122
123cat >expected <<\EOF
124'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
125'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
126EOF
127
128test_expect_success 'Check unformatted date fields output' '
129 (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
130 git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
3af82863 131 test_cmp expected actual
96b2d4fa
AP
132'
133
134test_expect_success 'Check format "default" formatted date fields output' '
135 f=default &&
136 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
137 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
3af82863 138 test_cmp expected actual
96b2d4fa
AP
139'
140
141# Don't know how to do relative check because I can't know when this script
142# is going to be run and can't fake the current time to git, and hence can't
143# provide expected output. Instead, I'll just make sure that "relative"
144# doesn't exit in error
145#
146#cat >expected <<\EOF
147#
148#EOF
149#
150test_expect_success 'Check format "relative" date fields output' '
151 f=relative &&
152 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
153 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
154'
155
156cat >expected <<\EOF
157'refs/heads/master' '2006-07-03' '2006-07-03'
158'refs/tags/testtag' '2006-07-03'
159EOF
160
161test_expect_success 'Check format "short" date fields output' '
162 f=short &&
163 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
164 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
3af82863 165 test_cmp expected actual
96b2d4fa
AP
166'
167
168cat >expected <<\EOF
169'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
170'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
171EOF
172
173test_expect_success 'Check format "local" date fields output' '
174 f=local &&
175 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
176 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
3af82863 177 test_cmp expected actual
96b2d4fa
AP
178'
179
180cat >expected <<\EOF
181'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
182'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
183EOF
184
185test_expect_success 'Check format "iso8601" date fields output' '
186 f=iso8601 &&
187 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
188 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
3af82863 189 test_cmp expected actual
96b2d4fa
AP
190'
191
192cat >expected <<\EOF
193'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
194'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
195EOF
196
197test_expect_success 'Check format "rfc2822" date fields output' '
198 f=rfc2822 &&
199 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
200 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
3af82863 201 test_cmp expected actual
96b2d4fa
AP
202'
203
c899a57c
LH
204cat >expected <<\EOF
205refs/heads/master
206refs/tags/testtag
207EOF
208
209test_expect_success 'Verify ascending sort' '
3604e7c5 210 git for-each-ref --format="%(refname)" --sort=refname >actual &&
3af82863 211 test_cmp expected actual
c899a57c
LH
212'
213
214
215cat >expected <<\EOF
216refs/tags/testtag
217refs/heads/master
218EOF
219
220test_expect_success 'Verify descending sort' '
3604e7c5 221 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
3af82863 222 test_cmp expected actual
c899a57c
LH
223'
224
c9ecf4f1
JS
225cat >expected <<\EOF
226'refs/heads/master'
227'refs/tags/testtag'
228EOF
229
230test_expect_success 'Quoting style: shell' '
231 git for-each-ref --shell --format="%(refname)" >actual &&
3af82863 232 test_cmp expected actual
c9ecf4f1
JS
233'
234
235test_expect_success 'Quoting style: perl' '
236 git for-each-ref --perl --format="%(refname)" >actual &&
3af82863 237 test_cmp expected actual
c9ecf4f1
JS
238'
239
240test_expect_success 'Quoting style: python' '
241 git for-each-ref --python --format="%(refname)" >actual &&
3af82863 242 test_cmp expected actual
c9ecf4f1
JS
243'
244
245cat >expected <<\EOF
246"refs/heads/master"
247"refs/tags/testtag"
248EOF
249
250test_expect_success 'Quoting style: tcl' '
251 git for-each-ref --tcl --format="%(refname)" >actual &&
3af82863 252 test_cmp expected actual
c9ecf4f1
JS
253'
254
255for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
256 test_expect_success "more than one quoting style: $i" "
257 git for-each-ref $i 2>&1 | (read line &&
258 case \$line in
259 \"error: more than one quoting style\"*) : happy;;
260 *) false
261 esac)
262 "
263done
c899a57c 264
e276c26b
JH
265test_expect_success 'an unusual tag with an incomplete line' '
266
267 git tag -m "bogo" bogo &&
268 bogo=$(git cat-file tag bogo) &&
269 bogo=$(printf "%s" "$bogo" | git mktag) &&
270 git tag -f bogo "$bogo" &&
271 git for-each-ref --format "%(body)" refs/tags/bogo
272
273'
274
96b2d4fa 275test_done