]>
Commit | Line | Data |
---|---|---|
96b2d4fa AP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Andy Parkins | |
4 | # | |
5 | ||
6 | test_description='for-each-ref test' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
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 | |
18 | } | |
19 | ||
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 | |
27 | ' | |
28 | ||
d2bf48d2 JK |
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 | |
38 | " | |
39 | } | |
40 | ||
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 | |
68 | ' | |
69 | ||
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 | |
96b2d4fa AP |
97 | ' |
98 | ||
41ac414e | 99 | test_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 | ||
103 | test_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 | ||
110 | test_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 | 119 | test_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 | ||
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' | |
126 | EOF | |
127 | ||
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 && | |
3af82863 | 131 | test_cmp expected actual |
96b2d4fa AP |
132 | ' |
133 | ||
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 && | |
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 | # | |
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 | |
154 | ' | |
155 | ||
156 | cat >expected <<\EOF | |
157 | 'refs/heads/master' '2006-07-03' '2006-07-03' | |
158 | 'refs/tags/testtag' '2006-07-03' | |
159 | EOF | |
160 | ||
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 && | |
3af82863 | 165 | test_cmp expected actual |
96b2d4fa AP |
166 | ' |
167 | ||
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' | |
171 | EOF | |
172 | ||
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 && | |
3af82863 | 177 | test_cmp expected actual |
96b2d4fa AP |
178 | ' |
179 | ||
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' | |
183 | EOF | |
184 | ||
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 && | |
3af82863 | 189 | test_cmp expected actual |
96b2d4fa AP |
190 | ' |
191 | ||
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' | |
195 | EOF | |
196 | ||
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 && | |
3af82863 | 201 | test_cmp expected actual |
96b2d4fa AP |
202 | ' |
203 | ||
c899a57c LH |
204 | cat >expected <<\EOF |
205 | refs/heads/master | |
206 | refs/tags/testtag | |
207 | EOF | |
208 | ||
209 | test_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 | ||
215 | cat >expected <<\EOF | |
216 | refs/tags/testtag | |
217 | refs/heads/master | |
218 | EOF | |
219 | ||
220 | test_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 |
225 | cat >expected <<\EOF |
226 | 'refs/heads/master' | |
227 | 'refs/tags/testtag' | |
228 | EOF | |
229 | ||
230 | test_expect_success 'Quoting style: shell' ' | |
231 | git for-each-ref --shell --format="%(refname)" >actual && | |
3af82863 | 232 | test_cmp expected actual |
c9ecf4f1 JS |
233 | ' |
234 | ||
235 | test_expect_success 'Quoting style: perl' ' | |
236 | git for-each-ref --perl --format="%(refname)" >actual && | |
3af82863 | 237 | test_cmp expected actual |
c9ecf4f1 JS |
238 | ' |
239 | ||
240 | test_expect_success 'Quoting style: python' ' | |
241 | git for-each-ref --python --format="%(refname)" >actual && | |
3af82863 | 242 | test_cmp expected actual |
c9ecf4f1 JS |
243 | ' |
244 | ||
245 | cat >expected <<\EOF | |
246 | "refs/heads/master" | |
247 | "refs/tags/testtag" | |
248 | EOF | |
249 | ||
250 | test_expect_success 'Quoting style: tcl' ' | |
251 | git for-each-ref --tcl --format="%(refname)" >actual && | |
3af82863 | 252 | test_cmp expected actual |
c9ecf4f1 JS |
253 | ' |
254 | ||
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) | |
262 | " | |
263 | done | |
c899a57c | 264 | |
e276c26b JH |
265 | test_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 | 275 | test_done |