add --path option to git hash-object
[git.git] / t / t6300-for-each-ref.sh
bloba3c8941c726d77fd993a3cfcd7fde4e9aa43da74
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_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
41 test_atom head refname refs/heads/master
42 test_atom head objecttype commit
43 test_atom head objectsize 171
44 test_atom head objectname 67a36f10722846e891fbada1ba48ed035de75581
45 test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f
46 test_atom head parent ''
47 test_atom head numparent 0
48 test_atom head object ''
49 test_atom head type ''
50 test_atom head author 'A U Thor <author@example.com> 1151939924 +0200'
51 test_atom head authorname 'A U Thor'
52 test_atom head authoremail '<author@example.com>'
53 test_atom head authordate 'Mon Jul 3 17:18:44 2006 +0200'
54 test_atom head committer 'C O Mitter <committer@example.com> 1151939923 +0200'
55 test_atom head committername 'C O Mitter'
56 test_atom head committeremail '<committer@example.com>'
57 test_atom head committerdate 'Mon Jul 3 17:18:43 2006 +0200'
58 test_atom head tag ''
59 test_atom head tagger ''
60 test_atom head taggername ''
61 test_atom head taggeremail ''
62 test_atom head taggerdate ''
63 test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200'
64 test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200'
65 test_atom head subject 'Initial'
66 test_atom head body ''
67 test_atom head contents 'Initial
70 test_atom tag refname refs/tags/testtag
71 test_atom tag objecttype tag
72 test_atom tag objectsize 154
73 test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322
74 test_atom tag tree ''
75 test_atom tag parent ''
76 test_atom tag numparent ''
77 test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
78 test_atom tag type 'commit'
79 test_atom tag author ''
80 test_atom tag authorname ''
81 test_atom tag authoremail ''
82 test_atom tag authordate ''
83 test_atom tag committer ''
84 test_atom tag committername ''
85 test_atom tag committeremail ''
86 test_atom tag committerdate ''
87 test_atom tag tag 'testtag'
88 test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200'
89 test_atom tag taggername 'C O Mitter'
90 test_atom tag taggeremail '<committer@example.com>'
91 test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200'
92 test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200'
93 test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200'
94 test_atom tag subject 'Tagging at 1151939927'
95 test_atom tag body ''
96 test_atom tag contents 'Tagging at 1151939927
99 test_expect_success 'Check invalid atoms names are errors' '
100 test_must_fail git-for-each-ref --format="%(INVALID)" refs/heads
103 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
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
110 test_expect_success 'Check valid format specifiers for date fields' '
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
119 test_expect_success 'Check invalid format specifiers are errors' '
120 test_must_fail git-for-each-ref --format="%(authordate:INVALID)" refs/heads
123 cat >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'
128 test_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 &&
131 test_cmp expected actual
134 test_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 &&
138 test_cmp expected actual
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
146 #cat >expected <<\EOF
148 #EOF
150 test_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
156 cat >expected <<\EOF
157 'refs/heads/master' '2006-07-03' '2006-07-03'
158 'refs/tags/testtag' '2006-07-03'
161 test_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 &&
165 test_cmp expected actual
168 cat >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'
173 test_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 &&
177 test_cmp expected actual
180 cat >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'
185 test_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 &&
189 test_cmp expected actual
192 cat >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'
197 test_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 &&
201 test_cmp expected actual
204 cat >expected <<\EOF
205 refs/heads/master
206 refs/tags/testtag
209 test_expect_success 'Verify ascending sort' '
210 git-for-each-ref --format="%(refname)" --sort=refname >actual &&
211 test_cmp expected actual
215 cat >expected <<\EOF
216 refs/tags/testtag
217 refs/heads/master
220 test_expect_success 'Verify descending sort' '
221 git-for-each-ref --format="%(refname)" --sort=-refname >actual &&
222 test_cmp expected actual
225 cat >expected <<\EOF
226 'refs/heads/master'
227 'refs/tags/testtag'
230 test_expect_success 'Quoting style: shell' '
231 git for-each-ref --shell --format="%(refname)" >actual &&
232 test_cmp expected actual
235 test_expect_success 'Quoting style: perl' '
236 git for-each-ref --perl --format="%(refname)" >actual &&
237 test_cmp expected actual
240 test_expect_success 'Quoting style: python' '
241 git for-each-ref --python --format="%(refname)" >actual &&
242 test_cmp expected actual
245 cat >expected <<\EOF
246 "refs/heads/master"
247 "refs/tags/testtag"
250 test_expect_success 'Quoting style: tcl' '
251 git for-each-ref --tcl --format="%(refname)" >actual &&
252 test_cmp expected actual
255 for 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)
263 done
265 test_done