builtin-remote: prune remotes correctly that were added with --mirror
[git/mingw.git] / t / t6300-for-each-ref.sh
blobf46ec93c83d990c0887d3ff9d59f9d365b4d5eed
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 'Check atom names are valid' '
30 bad=
31 for token in \
32 refname objecttype objectsize objectname tree parent \
33 numparent object type author authorname authoremail \
34 authordate committer committername committeremail \
35 committerdate tag tagger taggername taggeremail \
36 taggerdate creator creatordate subject body contents
38 git for-each-ref --format="$token=%($token)" refs/heads || {
39 bad=$token
40 break
42 done
43 test -z "$bad"
46 test_expect_success 'Check invalid atoms names are errors' '
47 ! git-for-each-ref --format="%(INVALID)" refs/heads
50 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
51 git-for-each-ref --format="%(authordate)" refs/heads &&
52 git-for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
53 git-for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
54 git-for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
57 test_expect_success 'Check valid format specifiers for date fields' '
58 git-for-each-ref --format="%(authordate:default)" refs/heads &&
59 git-for-each-ref --format="%(authordate:relative)" refs/heads &&
60 git-for-each-ref --format="%(authordate:short)" refs/heads &&
61 git-for-each-ref --format="%(authordate:local)" refs/heads &&
62 git-for-each-ref --format="%(authordate:iso8601)" refs/heads &&
63 git-for-each-ref --format="%(authordate:rfc2822)" refs/heads
66 test_expect_success 'Check invalid format specifiers are errors' '
67 ! git-for-each-ref --format="%(authordate:INVALID)" refs/heads
70 cat >expected <<\EOF
71 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
72 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
73 EOF
75 test_expect_success 'Check unformatted date fields output' '
76 (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
77 git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
78 git diff expected actual
81 test_expect_success 'Check format "default" formatted date fields output' '
82 f=default &&
83 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
84 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
85 git diff expected actual
88 # Don't know how to do relative check because I can't know when this script
89 # is going to be run and can't fake the current time to git, and hence can't
90 # provide expected output. Instead, I'll just make sure that "relative"
91 # doesn't exit in error
93 #cat >expected <<\EOF
95 #EOF
97 test_expect_success 'Check format "relative" date fields output' '
98 f=relative &&
99 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
100 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
103 cat >expected <<\EOF
104 'refs/heads/master' '2006-07-03' '2006-07-03'
105 'refs/tags/testtag' '2006-07-03'
108 test_expect_success 'Check format "short" date fields output' '
109 f=short &&
110 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
111 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
112 git diff expected actual
115 cat >expected <<\EOF
116 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
117 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
120 test_expect_success 'Check format "local" date fields output' '
121 f=local &&
122 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
123 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
124 git diff expected actual
127 cat >expected <<\EOF
128 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
129 'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
132 test_expect_success 'Check format "iso8601" date fields output' '
133 f=iso8601 &&
134 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
135 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
136 git diff expected actual
139 cat >expected <<\EOF
140 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
141 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
144 test_expect_success 'Check format "rfc2822" date fields output' '
145 f=rfc2822 &&
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 git diff expected actual
151 cat >expected <<\EOF
152 refs/heads/master
153 refs/tags/testtag
156 test_expect_success 'Verify ascending sort' '
157 git-for-each-ref --format="%(refname)" --sort=refname >actual &&
158 git diff expected actual
162 cat >expected <<\EOF
163 refs/tags/testtag
164 refs/heads/master
167 test_expect_success 'Verify descending sort' '
168 git-for-each-ref --format="%(refname)" --sort=-refname >actual &&
169 git diff expected actual
172 cat >expected <<\EOF
173 'refs/heads/master'
174 'refs/tags/testtag'
177 test_expect_success 'Quoting style: shell' '
178 git for-each-ref --shell --format="%(refname)" >actual &&
179 git diff expected actual
182 test_expect_success 'Quoting style: perl' '
183 git for-each-ref --perl --format="%(refname)" >actual &&
184 git diff expected actual
187 test_expect_success 'Quoting style: python' '
188 git for-each-ref --python --format="%(refname)" >actual &&
189 git diff expected actual
192 cat >expected <<\EOF
193 "refs/heads/master"
194 "refs/tags/testtag"
197 test_expect_success 'Quoting style: tcl' '
198 git for-each-ref --tcl --format="%(refname)" >actual &&
199 git diff expected actual
202 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
203 test_expect_success "more than one quoting style: $i" "
204 git for-each-ref $i 2>&1 | (read line &&
205 case \$line in
206 \"error: more than one quoting style\"*) : happy;;
207 *) false
208 esac)
210 done
212 test_done