push test: simplify check of push result
This test checks each ref with code like the following: r=$(git show-ref -s --verify refs/$ref) && test "z$r" = "z$the_first_commit" Afterward it counts refs: test 1 = $(git for-each-ref refs/remotes/origin | wc -l) Simpler to test the number and values of relevant refs in for-each-ref output at the same time using test_cmp. This makes the test more readable and provides more helpful "./t5516-push-push.sh -v" output when the test fails. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Mar 18, 2013 at 16:13 UTC
848575d833ca0d9d47db372348576f3b98bd19b7
1 file changed
+51
-63
t/t5516-fetch-push.sh
+51
-63
@@ -30,11 +30,10 @@ mk_test () {
30
cd testrepo &&
31
for ref in "$@"
32
do
33
- r=$(git show-ref -s --verify refs/$ref) &&
34
- test "z$r" = "z$the_first_commit" || {
35
- echo "Oops, refs/$ref is wrong"
36
- exit 1
37
- }
33
+ echo "$the_first_commit" >expect &&
34
+ git show-ref -s --verify refs/$ref >actual &&
35
+ test_cmp expect actual ||
36
+ exit
37
done &&
38
git fsck --full
39
)
@@ -82,15 +81,13 @@ mk_child() {
81
check_push_result () {
82
(
83
cd testrepo &&
85
- it="$1" &&
86
- shift
84
+ echo "$1" >expect &&
85
+ shift &&
86
for ref in "$@"
87
do
89
- r=$(git show-ref -s --verify refs/$ref) &&
90
- test "z$r" = "z$it" || {
91
- echo "Oops, refs/$ref is wrong"
92
- exit 1
93
- }
88
+ git show-ref -s --verify refs/$ref >actual &&
89
+ test_cmp expect actual ||
90
+ exit
91
done &&
92
git fsck --full
93
)
@@ -118,10 +115,9 @@ test_expect_success 'fetch without wildcard' '
115
cd testrepo &&
116
git fetch .. refs/heads/master:refs/remotes/origin/master &&
117
121
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
122
- test "z$r" = "z$the_commit" &&
123
-
124
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
118
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
119
+ git for-each-ref refs/remotes/origin >actual &&
120
+ test_cmp expect actual
121
)
122
'
123
@@ -133,10 +129,9 @@ test_expect_success 'fetch with wildcard' '
129
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
130
git fetch up &&
131
136
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
137
- test "z$r" = "z$the_commit" &&
138
-
139
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
132
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
133
+ git for-each-ref refs/remotes/origin >actual &&
134
+ test_cmp expect actual
135
)
136
'
137
@@ -150,10 +145,9 @@ test_expect_success 'fetch with insteadOf' '
145
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
146
git fetch up &&
147
153
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
154
- test "z$r" = "z$the_commit" &&
155
-
156
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
148
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
149
+ git for-each-ref refs/remotes/origin >actual &&
150
+ test_cmp expect actual
151
)
152
'
153
@@ -167,10 +161,9 @@ test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
161
git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
162
git fetch up &&
163
170
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
171
- test "z$r" = "z$the_commit" &&
172
-
173
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
164
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
165
+ git for-each-ref refs/remotes/origin >actual &&
166
+ test_cmp expect actual
167
)
168
'
169
@@ -180,10 +173,9 @@ test_expect_success 'push without wildcard' '
173
git push testrepo refs/heads/master:refs/remotes/origin/master &&
174
(
175
cd testrepo &&
183
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
184
- test "z$r" = "z$the_commit" &&
185
-
186
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
176
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
177
+ git for-each-ref refs/remotes/origin >actual &&
178
+ test_cmp expect actual
179
)
180
'
181
@@ -193,10 +185,9 @@ test_expect_success 'push with wildcard' '
185
git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
186
(
187
cd testrepo &&
196
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
197
- test "z$r" = "z$the_commit" &&
198
-
199
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
188
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
189
+ git for-each-ref refs/remotes/origin >actual &&
190
+ test_cmp expect actual
191
)
192
'
193
@@ -207,10 +198,9 @@ test_expect_success 'push with insteadOf' '
198
git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
199
(
200
cd testrepo &&
210
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
211
- test "z$r" = "z$the_commit" &&
212
-
213
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
201
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
202
+ git for-each-ref refs/remotes/origin >actual &&
203
+ test_cmp expect actual
204
)
205
'
206
@@ -221,10 +211,9 @@ test_expect_success 'push with pushInsteadOf' '
211
git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
212
(
213
cd testrepo &&
224
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
225
- test "z$r" = "z$the_commit" &&
226
-
227
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
214
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
215
+ git for-each-ref refs/remotes/origin >actual &&
216
+ test_cmp expect actual
217
)
218
'
219
@@ -237,10 +226,9 @@ test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf
226
git push r refs/heads/master:refs/remotes/origin/master &&
227
(
228
cd testrepo &&
240
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
241
- test "z$r" = "z$the_commit" &&
242
-
243
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
229
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
230
+ git for-each-ref refs/remotes/origin >actual &&
231
+ test_cmp expect actual
232
)
233
'
234
@@ -827,9 +815,9 @@ test_expect_success 'fetch with branches' '
815
(
816
cd testrepo &&
817
git fetch branch1 &&
830
- r=$(git show-ref -s --verify refs/heads/branch1) &&
831
- test "z$r" = "z$the_commit" &&
832
- test 1 = $(git for-each-ref refs/heads | wc -l)
818
+ echo "$the_commit commit refs/heads/branch1" >expect &&
819
+ git for-each-ref refs/heads >actual &&
820
+ test_cmp expect actual
821
) &&
822
git checkout master
823
'
@@ -840,9 +828,9 @@ test_expect_success 'fetch with branches containing #' '
828
(
829
cd testrepo &&
830
git fetch branch2 &&
843
- r=$(git show-ref -s --verify refs/heads/branch2) &&
844
- test "z$r" = "z$the_first_commit" &&
845
- test 1 = $(git for-each-ref refs/heads | wc -l)
831
+ echo "$the_first_commit commit refs/heads/branch2" >expect &&
832
+ git for-each-ref refs/heads >actual &&
833
+ test_cmp expect actual
834
) &&
835
git checkout master
836
'
@@ -854,9 +842,9 @@ test_expect_success 'push with branches' '
842
git push branch1 &&
843
(
844
cd testrepo &&
857
- r=$(git show-ref -s --verify refs/heads/master) &&
858
- test "z$r" = "z$the_first_commit" &&
859
- test 1 = $(git for-each-ref refs/heads | wc -l)
845
+ echo "$the_first_commit commit refs/heads/master" >expect &&
846
+ git for-each-ref refs/heads >actual &&
847
+ test_cmp expect actual
848
)
849
'
850
@@ -866,9 +854,9 @@ test_expect_success 'push with branches containing #' '
854
git push branch2 &&
855
(
856
cd testrepo &&
869
- r=$(git show-ref -s --verify refs/heads/branch3) &&
870
- test "z$r" = "z$the_first_commit" &&
871
- test 1 = $(git for-each-ref refs/heads | wc -l)
857
+ echo "$the_first_commit commit refs/heads/branch3" >expect &&
858
+ git for-each-ref refs/heads >actual &&
859
+ test_cmp expect actual
860
) &&
861
git checkout master
862
'
@@ -951,9 +939,9 @@ test_expect_success 'push --porcelain' '
939
git push >.git/bar --porcelain testrepo refs/heads/master:refs/remotes/origin/master &&
940
(
941
cd testrepo &&
954
- r=$(git show-ref -s --verify refs/remotes/origin/master) &&
955
- test "z$r" = "z$the_commit" &&
956
- test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
942
+ echo "$the_commit commit refs/remotes/origin/master" >expect &&
943
+ git for-each-ref refs/remotes/origin >actual &&
944
+ test_cmp expect actual
945
) &&
946
test_cmp .git/foo .git/bar
947
'