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
'Check atom names are valid' '
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 || {
46 test_expect_failure
'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_failure
'Check invalid format specifiers are errors' '
67 git-for-each-ref --format="%(authordate:INVALID)" refs/heads
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'
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' '
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
97 test_expect_success
'Check format "relative" date fields output' '
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
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' '
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
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' '
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
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' '
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
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' '
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
156 test_expect_success
'Verify ascending sort' '
157 git-for-each-ref --format="%(refname)" --sort=refname >actual &&
158 git diff expected actual
167 test_expect_success
'Verify descending sort' '
168 git-for-each-ref --format="%(refname)" --sort=-refname >actual &&
169 git diff expected actual
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
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 &&
206 \"error: more than one quoting style\"*) : happy;;