merge-recursive: use "up-to-date" instead of "uptodate" in error message for consistency
[alt-git.git] / t / t6300-for-each-ref.sh
blob7dc8a510c7f33d048cd3268424298fdda2f8c2bb
1 #!/bin/sh
3 # Copyright (c) 2007 Andy Parkins
6 test_description='for-each-ref test'
8 . ./test-lib.sh
10 # Mon Jul 3 15:18:43 2006 +0000
11 datestamp=1151939923
12 setdate_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
20 test_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
29 test_expect_success 'Create upstream config' '
30 git update-ref refs/remotes/origin/master master &&
31 git remote add origin nowhere &&
32 git config branch.master.remote origin &&
33 git config branch.master.merge refs/heads/master
36 test_atom() {
37 case "$1" in
38 head) ref=refs/heads/master ;;
39 tag) ref=refs/tags/testtag ;;
40 esac
41 printf '%s\n' "$3" >expected
42 test_expect_${4:-success} "basic atom: $1 $2" "
43 git for-each-ref --format='%($2)' $ref >actual &&
44 test_cmp expected actual
48 test_atom head refname refs/heads/master
49 test_atom head upstream refs/remotes/origin/master
50 test_atom head objecttype commit
51 test_atom head objectsize 171
52 test_atom head objectname 67a36f10722846e891fbada1ba48ed035de75581
53 test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f
54 test_atom head parent ''
55 test_atom head numparent 0
56 test_atom head object ''
57 test_atom head type ''
58 test_atom head author 'A U Thor <author@example.com> 1151939924 +0200'
59 test_atom head authorname 'A U Thor'
60 test_atom head authoremail '<author@example.com>'
61 test_atom head authordate 'Mon Jul 3 17:18:44 2006 +0200'
62 test_atom head committer 'C O Mitter <committer@example.com> 1151939923 +0200'
63 test_atom head committername 'C O Mitter'
64 test_atom head committeremail '<committer@example.com>'
65 test_atom head committerdate 'Mon Jul 3 17:18:43 2006 +0200'
66 test_atom head tag ''
67 test_atom head tagger ''
68 test_atom head taggername ''
69 test_atom head taggeremail ''
70 test_atom head taggerdate ''
71 test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200'
72 test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200'
73 test_atom head subject 'Initial'
74 test_atom head body ''
75 test_atom head contents 'Initial
78 test_atom tag refname refs/tags/testtag
79 test_atom tag upstream ''
80 test_atom tag objecttype tag
81 test_atom tag objectsize 154
82 test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322
83 test_atom tag tree ''
84 test_atom tag parent ''
85 test_atom tag numparent ''
86 test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
87 test_atom tag type 'commit'
88 test_atom tag author ''
89 test_atom tag authorname ''
90 test_atom tag authoremail ''
91 test_atom tag authordate ''
92 test_atom tag committer ''
93 test_atom tag committername ''
94 test_atom tag committeremail ''
95 test_atom tag committerdate ''
96 test_atom tag tag 'testtag'
97 test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200'
98 test_atom tag taggername 'C O Mitter'
99 test_atom tag taggeremail '<committer@example.com>'
100 test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200'
101 test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200'
102 test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200'
103 test_atom tag subject 'Tagging at 1151939927'
104 test_atom tag body ''
105 test_atom tag contents 'Tagging at 1151939927
108 test_expect_success 'Check invalid atoms names are errors' '
109 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
112 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
113 git for-each-ref --format="%(authordate)" refs/heads &&
114 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
115 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
116 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
119 test_expect_success 'Check valid format specifiers for date fields' '
120 git for-each-ref --format="%(authordate:default)" refs/heads &&
121 git for-each-ref --format="%(authordate:relative)" refs/heads &&
122 git for-each-ref --format="%(authordate:short)" refs/heads &&
123 git for-each-ref --format="%(authordate:local)" refs/heads &&
124 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
125 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
128 test_expect_success 'Check invalid format specifiers are errors' '
129 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
132 cat >expected <<\EOF
133 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
134 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
137 test_expect_success 'Check unformatted date fields output' '
138 (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
139 git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
140 test_cmp expected actual
143 test_expect_success 'Check format "default" formatted date fields output' '
144 f=default &&
145 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
146 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
147 test_cmp expected actual
150 # Don't know how to do relative check because I can't know when this script
151 # is going to be run and can't fake the current time to git, and hence can't
152 # provide expected output. Instead, I'll just make sure that "relative"
153 # doesn't exit in error
155 #cat >expected <<\EOF
157 #EOF
159 test_expect_success 'Check format "relative" date fields output' '
160 f=relative &&
161 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
162 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
165 cat >expected <<\EOF
166 'refs/heads/master' '2006-07-03' '2006-07-03'
167 'refs/tags/testtag' '2006-07-03'
170 test_expect_success 'Check format "short" date fields output' '
171 f=short &&
172 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
173 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
174 test_cmp expected actual
177 cat >expected <<\EOF
178 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
179 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
182 test_expect_success 'Check format "local" date fields output' '
183 f=local &&
184 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
185 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
186 test_cmp expected actual
189 cat >expected <<\EOF
190 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
191 'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
194 test_expect_success 'Check format "iso8601" date fields output' '
195 f=iso8601 &&
196 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
197 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
198 test_cmp expected actual
201 cat >expected <<\EOF
202 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
203 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
206 test_expect_success 'Check format "rfc2822" date fields output' '
207 f=rfc2822 &&
208 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
209 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
210 test_cmp expected actual
213 cat >expected <<\EOF
214 refs/heads/master
215 refs/remotes/origin/master
216 refs/tags/testtag
219 test_expect_success 'Verify ascending sort' '
220 git for-each-ref --format="%(refname)" --sort=refname >actual &&
221 test_cmp expected actual
225 cat >expected <<\EOF
226 refs/tags/testtag
227 refs/remotes/origin/master
228 refs/heads/master
231 test_expect_success 'Verify descending sort' '
232 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
233 test_cmp expected actual
236 cat >expected <<\EOF
237 'refs/heads/master'
238 'refs/remotes/origin/master'
239 'refs/tags/testtag'
242 test_expect_success 'Quoting style: shell' '
243 git for-each-ref --shell --format="%(refname)" >actual &&
244 test_cmp expected actual
247 test_expect_success 'Quoting style: perl' '
248 git for-each-ref --perl --format="%(refname)" >actual &&
249 test_cmp expected actual
252 test_expect_success 'Quoting style: python' '
253 git for-each-ref --python --format="%(refname)" >actual &&
254 test_cmp expected actual
257 cat >expected <<\EOF
258 "refs/heads/master"
259 "refs/remotes/origin/master"
260 "refs/tags/testtag"
263 test_expect_success 'Quoting style: tcl' '
264 git for-each-ref --tcl --format="%(refname)" >actual &&
265 test_cmp expected actual
268 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
269 test_expect_success "more than one quoting style: $i" "
270 git for-each-ref $i 2>&1 | (read line &&
271 case \$line in
272 \"error: more than one quoting style\"*) : happy;;
273 *) false
274 esac)
276 done
278 cat >expected <<\EOF
279 master
280 testtag
283 test_expect_success 'Check short refname format' '
284 (git for-each-ref --format="%(refname:short)" refs/heads &&
285 git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
286 test_cmp expected actual
289 cat >expected <<EOF
290 origin/master
293 test_expect_success 'Check short upstream format' '
294 git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
295 test_cmp expected actual
298 cat >expected <<EOF
299 67a36f1
302 test_expect_success 'Check short objectname format' '
303 git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
304 test_cmp expected actual
307 test_expect_success 'Check for invalid refname format' '
308 test_must_fail git for-each-ref --format="%(refname:INVALID)"
311 cat >expected <<\EOF
312 heads/master
313 tags/master
316 test_expect_success 'Check ambiguous head and tag refs (strict)' '
317 git config --bool core.warnambiguousrefs true &&
318 git checkout -b newtag &&
319 echo "Using $datestamp" > one &&
320 git add one &&
321 git commit -m "Branch" &&
322 setdate_and_increment &&
323 git tag -m "Tagging at $datestamp" master &&
324 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
325 test_cmp expected actual
328 cat >expected <<\EOF
329 heads/master
330 master
333 test_expect_success 'Check ambiguous head and tag refs (loose)' '
334 git config --bool core.warnambiguousrefs false &&
335 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
336 test_cmp expected actual
339 cat >expected <<\EOF
340 heads/ambiguous
341 ambiguous
344 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
345 git checkout master &&
346 git tag ambiguous testtag^0 &&
347 git branch ambiguous testtag^0 &&
348 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
349 test_cmp expected actual
352 test_expect_success 'an unusual tag with an incomplete line' '
354 git tag -m "bogo" bogo &&
355 bogo=$(git cat-file tag bogo) &&
356 bogo=$(printf "%s" "$bogo" | git mktag) &&
357 git tag -f bogo "$bogo" &&
358 git for-each-ref --format "%(body)" refs/tags/bogo
362 test_done