3 # Copyright (c) 2007 Andy Parkins
6 test_description
='for-each-ref test'
10 # Mon Jul 3 15:18:43 2006 +0000
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 &&
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
38 head) ref
=refs
/heads
/master
;;
39 tag
) ref
=refs
/tags
/testtag
;;
42 printf '%s\n' "$3" >expected
43 test_expect_
${4:-success} "basic atom: $1 $2" "
44 git for-each-ref --format='%($2)' $ref >actual &&
45 test_cmp expected actual
49 test_atom
head refname refs
/heads
/master
50 test_atom
head upstream refs
/remotes
/origin
/master
51 test_atom
head objecttype commit
52 test_atom
head objectsize
171
53 test_atom
head objectname
67a36f10722846e891fbada1ba48ed035de75581
54 test_atom
head tree
0e51c00fcb93dffc755546f27593d511e1bdb46f
55 test_atom
head parent
''
56 test_atom
head numparent
0
57 test_atom
head object
''
58 test_atom
head type ''
59 test_atom
head author
'A U Thor <author@example.com> 1151939924 +0200'
60 test_atom
head authorname
'A U Thor'
61 test_atom
head authoremail
'<author@example.com>'
62 test_atom
head authordate
'Mon Jul 3 17:18:44 2006 +0200'
63 test_atom
head committer
'C O Mitter <committer@example.com> 1151939923 +0200'
64 test_atom
head committername
'C O Mitter'
65 test_atom
head committeremail
'<committer@example.com>'
66 test_atom
head committerdate
'Mon Jul 3 17:18:43 2006 +0200'
68 test_atom
head tagger
''
69 test_atom
head taggername
''
70 test_atom
head taggeremail
''
71 test_atom
head taggerdate
''
72 test_atom
head creator
'C O Mitter <committer@example.com> 1151939923 +0200'
73 test_atom
head creatordate
'Mon Jul 3 17:18:43 2006 +0200'
74 test_atom
head subject
'Initial'
75 test_atom
head body
''
76 test_atom
head contents
'Initial
79 test_atom tag refname refs
/tags
/testtag
80 test_atom tag upstream
''
81 test_atom tag objecttype tag
82 test_atom tag objectsize
154
83 test_atom tag objectname
98b46b1d36e5b07909de1b3886224e3e81e87322
85 test_atom tag parent
''
86 test_atom tag numparent
''
87 test_atom tag object
'67a36f10722846e891fbada1ba48ed035de75581'
88 test_atom tag
type 'commit'
89 test_atom tag author
''
90 test_atom tag authorname
''
91 test_atom tag authoremail
''
92 test_atom tag authordate
''
93 test_atom tag committer
''
94 test_atom tag committername
''
95 test_atom tag committeremail
''
96 test_atom tag committerdate
''
97 test_atom tag tag
'testtag'
98 test_atom tag tagger
'C O Mitter <committer@example.com> 1151939925 +0200'
99 test_atom tag taggername
'C O Mitter'
100 test_atom tag taggeremail
'<committer@example.com>'
101 test_atom tag taggerdate
'Mon Jul 3 17:18:45 2006 +0200'
102 test_atom tag creator
'C O Mitter <committer@example.com> 1151939925 +0200'
103 test_atom tag creatordate
'Mon Jul 3 17:18:45 2006 +0200'
104 test_atom tag subject
'Tagging at 1151939927'
105 test_atom tag body
''
106 test_atom tag contents
'Tagging at 1151939927
109 test_expect_success
'Check invalid atoms names are errors' '
110 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
113 test_expect_success
'Check format specifiers are ignored in naming date atoms' '
114 git for-each-ref --format="%(authordate)" refs/heads &&
115 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
116 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
117 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
120 test_expect_success
'Check valid format specifiers for date fields' '
121 git for-each-ref --format="%(authordate:default)" refs/heads &&
122 git for-each-ref --format="%(authordate:relative)" refs/heads &&
123 git for-each-ref --format="%(authordate:short)" refs/heads &&
124 git for-each-ref --format="%(authordate:local)" refs/heads &&
125 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
126 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
129 test_expect_success
'Check invalid format specifiers are errors' '
130 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
134 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
135 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
138 test_expect_success
'Check unformatted date fields output' '
139 (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
140 git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
141 test_cmp expected actual
144 test_expect_success
'Check format "default" formatted date fields output' '
146 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
147 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
148 test_cmp expected actual
151 # Don't know how to do relative check because I can't know when this script
152 # is going to be run and can't fake the current time to git, and hence can't
153 # provide expected output. Instead, I'll just make sure that "relative"
154 # doesn't exit in error
156 #cat >expected <<\EOF
160 test_expect_success
'Check format "relative" date fields output' '
162 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
163 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
167 'refs/heads/master' '2006-07-03' '2006-07-03'
168 'refs/tags/testtag' '2006-07-03'
171 test_expect_success
'Check format "short" date fields output' '
173 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
174 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
175 test_cmp expected actual
179 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
180 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
183 test_expect_success
'Check format "local" date fields output' '
185 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
186 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
187 test_cmp expected actual
191 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
192 'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
195 test_expect_success
'Check format "iso8601" date fields output' '
197 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
198 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
199 test_cmp expected actual
203 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
204 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
207 test_expect_success
'Check format "rfc2822" date fields output' '
209 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
210 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
211 test_cmp expected actual
216 refs
/remotes
/origin
/master
220 test_expect_success
'Verify ascending sort' '
221 git for-each-ref --format="%(refname)" --sort=refname >actual &&
222 test_cmp expected actual
228 refs
/remotes
/origin
/master
232 test_expect_success
'Verify descending sort' '
233 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
234 test_cmp expected actual
239 'refs/remotes/origin/master'
243 test_expect_success
'Quoting style: shell' '
244 git for-each-ref --shell --format="%(refname)" >actual &&
245 test_cmp expected actual
248 test_expect_success
'Quoting style: perl' '
249 git for-each-ref --perl --format="%(refname)" >actual &&
250 test_cmp expected actual
253 test_expect_success
'Quoting style: python' '
254 git for-each-ref --python --format="%(refname)" >actual &&
255 test_cmp expected actual
260 "refs/remotes/origin/master"
264 test_expect_success
'Quoting style: tcl' '
265 git for-each-ref --tcl --format="%(refname)" >actual &&
266 test_cmp expected actual
269 for i
in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
270 test_expect_success
"more than one quoting style: $i" "
271 git for-each-ref $i 2>&1 | (read line &&
273 \"error: more than one quoting style\"*) : happy;;
284 test_expect_success
'Check short refname format' '
285 (git for-each-ref --format="%(refname:short)" refs/heads &&
286 git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
287 test_cmp expected actual
294 test_expect_success
'Check short upstream format' '
295 git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
296 test_cmp expected actual
303 test_expect_success
'Check short objectname format' '
304 git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
305 test_cmp expected actual
308 test_expect_success
'Check for invalid refname format' '
309 test_must_fail git for-each-ref --format="%(refname:INVALID)"
317 test_expect_success
'Check ambiguous head and tag refs (strict)' '
318 git config --bool core.warnambiguousrefs true &&
319 git checkout -b newtag &&
320 echo "Using $datestamp" > one &&
322 git commit -m "Branch" &&
323 setdate_and_increment &&
324 git tag -m "Tagging at $datestamp" master &&
325 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
326 test_cmp expected actual
334 test_expect_success
'Check ambiguous head and tag refs (loose)' '
335 git config --bool core.warnambiguousrefs false &&
336 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
337 test_cmp expected actual
345 test_expect_success
'Check ambiguous head and tag refs II (loose)' '
346 git checkout master &&
347 git tag ambiguous testtag^0 &&
348 git branch ambiguous testtag^0 &&
349 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
350 test_cmp expected actual
353 test_expect_success
'an unusual tag with an incomplete line' '
355 git tag -m "bogo" bogo &&
356 bogo=$(git cat-file tag bogo) &&
357 bogo=$(printf "%s" "$bogo" | git mktag) &&
358 git tag -f bogo "$bogo" &&
359 git for-each-ref --format "%(body)" refs/tags/bogo
363 test_expect_success
'create tag with subject and body content' '
370 git tag -F msg subject-body
372 test_atom refs
/tags
/subject-body subject
'the subject line'
373 test_atom refs
/tags
/subject-body body
'first body line
376 test_atom refs
/tags
/subject-body contents
'the subject line
382 test_expect_success
'create tag with multiline subject' '
390 git tag -F msg multiline
392 test_atom refs
/tags
/multiline subject
'first subject line second subject line'
393 test_atom refs
/tags
/multiline body
'first body line
396 test_atom refs
/tags
/multiline contents
'first subject line