changed added/conflicted checking order
[git/mingw/4msysgit/wingit-dll.git] / t / t6300-for-each-ref.sh
blob8052c86ad3516505765ab214f4801940c8cc1684
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 test_expect_success 'Check for invalid refname format' '
299 test_must_fail git for-each-ref --format="%(refname:INVALID)"
302 cat >expected <<\EOF
303 heads/master
304 tags/master
307 test_expect_success 'Check ambiguous head and tag refs (strict)' '
308 git config --bool core.warnambiguousrefs true &&
309 git checkout -b newtag &&
310 echo "Using $datestamp" > one &&
311 git add one &&
312 git commit -m "Branch" &&
313 setdate_and_increment &&
314 git tag -m "Tagging at $datestamp" master &&
315 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
316 test_cmp expected actual
319 cat >expected <<\EOF
320 heads/master
321 master
324 test_expect_success 'Check ambiguous head and tag refs (loose)' '
325 git config --bool core.warnambiguousrefs false &&
326 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
327 test_cmp expected actual
330 cat >expected <<\EOF
331 heads/ambiguous
332 ambiguous
335 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
336 git checkout master &&
337 git tag ambiguous testtag^0 &&
338 git branch ambiguous testtag^0 &&
339 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
340 test_cmp expected actual
343 test_expect_success 'an unusual tag with an incomplete line' '
345 git tag -m "bogo" bogo &&
346 bogo=$(git cat-file tag bogo) &&
347 bogo=$(printf "%s" "$bogo" | git mktag) &&
348 git tag -f bogo "$bogo" &&
349 git for-each-ref --format "%(body)" refs/tags/bogo
353 test_done