@@ -157,106 +157,6 @@ test_expect_success 'want-ref with ref we already have commit for' '
157
157
check_output
158
158
'
159
159
160
- . " $TEST_DIRECTORY " /lib-httpd.sh
161
- start_httpd
162
-
163
- REPO=" $HTTPD_DOCUMENT_ROOT_PATH /repo"
164
- LOCAL_PRISTINE=" $( pwd) /local_pristine"
165
-
166
- test_expect_success ' setup repos for change-while-negotiating test' '
167
- (
168
- git init "$REPO" &&
169
- cd "$REPO" &&
170
- >.git/git-daemon-export-ok &&
171
- test_commit m1 &&
172
- git tag -d m1 &&
173
-
174
- # Local repo with many commits (so that negotiation will take
175
- # more than 1 request/response pair)
176
- git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
177
- cd "$LOCAL_PRISTINE" &&
178
- git checkout -b side &&
179
- test_commit_bulk --id=s 33 &&
180
-
181
- # Add novel commits to upstream
182
- git checkout master &&
183
- cd "$REPO" &&
184
- test_commit m2 &&
185
- test_commit m3 &&
186
- git tag -d m2 m3
187
- ) &&
188
- git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_sed/repo" &&
189
- git -C "$LOCAL_PRISTINE" config protocol.version 2
190
- '
191
-
192
- inconsistency () {
193
- # Simulate that the server initially reports $2 as the ref
194
- # corresponding to $1, and after that, $1 as the ref corresponding to
195
- # $1. This corresponds to the real-life situation where the server's
196
- # repository appears to change during negotiation, for example, when
197
- # different servers in a load-balancing arrangement serve (stateless)
198
- # RPCs during a single negotiation.
199
- printf " s/%s/%s/" \
200
- $( git -C " $REPO " rev-parse $1 | tr -d " \n" ) \
201
- $( git -C " $REPO " rev-parse $2 | tr -d " \n" ) \
202
- > " $HTTPD_ROOT_PATH /one-time-sed"
203
- }
204
-
205
- test_expect_success ' server is initially ahead - no ref in want' '
206
- git -C "$REPO" config uploadpack.allowRefInWant false &&
207
- rm -rf local &&
208
- cp -r "$LOCAL_PRISTINE" local &&
209
- inconsistency master 1234567890123456789012345678901234567890 &&
210
- test_must_fail git -C local fetch 2>err &&
211
- test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
212
- '
213
-
214
- test_expect_success ' server is initially ahead - ref in want' '
215
- git -C "$REPO" config uploadpack.allowRefInWant true &&
216
- rm -rf local &&
217
- cp -r "$LOCAL_PRISTINE" local &&
218
- inconsistency master 1234567890123456789012345678901234567890 &&
219
- git -C local fetch &&
220
-
221
- git -C "$REPO" rev-parse --verify master >expected &&
222
- git -C local rev-parse --verify refs/remotes/origin/master >actual &&
223
- test_cmp expected actual
224
- '
225
-
226
- test_expect_success ' server is initially behind - no ref in want' '
227
- git -C "$REPO" config uploadpack.allowRefInWant false &&
228
- rm -rf local &&
229
- cp -r "$LOCAL_PRISTINE" local &&
230
- inconsistency master "master^" &&
231
- git -C local fetch &&
232
-
233
- git -C "$REPO" rev-parse --verify "master^" >expected &&
234
- git -C local rev-parse --verify refs/remotes/origin/master >actual &&
235
- test_cmp expected actual
236
- '
237
-
238
- test_expect_success ' server is initially behind - ref in want' '
239
- git -C "$REPO" config uploadpack.allowRefInWant true &&
240
- rm -rf local &&
241
- cp -r "$LOCAL_PRISTINE" local &&
242
- inconsistency master "master^" &&
243
- git -C local fetch &&
244
-
245
- git -C "$REPO" rev-parse --verify "master" >expected &&
246
- git -C local rev-parse --verify refs/remotes/origin/master >actual &&
247
- test_cmp expected actual
248
- '
249
-
250
- test_expect_success ' server loses a ref - ref in want' '
251
- git -C "$REPO" config uploadpack.allowRefInWant true &&
252
- rm -rf local &&
253
- cp -r "$LOCAL_PRISTINE" local &&
254
- echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
255
- test_must_fail git -C local fetch 2>err &&
256
-
257
- test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
258
- '
259
-
260
160
REPO=" $( pwd) /repo"
261
161
LOCAL_PRISTINE=" $( pwd) /local_pristine"
262
162
@@ -372,4 +272,108 @@ test_expect_success 'fetching with wildcard that matches multiple refs' '
372
272
grep "want-ref refs/heads/o/bar" log
373
273
'
374
274
275
+ . " $TEST_DIRECTORY " /lib-httpd.sh
276
+ start_httpd
277
+
278
+ REPO=" $HTTPD_DOCUMENT_ROOT_PATH /repo"
279
+ LOCAL_PRISTINE=" $( pwd) /local_pristine"
280
+
281
+ test_expect_success ' setup repos for change-while-negotiating test' '
282
+ (
283
+ git init "$REPO" &&
284
+ cd "$REPO" &&
285
+ >.git/git-daemon-export-ok &&
286
+ test_commit m1 &&
287
+ git tag -d m1 &&
288
+
289
+ # Local repo with many commits (so that negotiation will take
290
+ # more than 1 request/response pair)
291
+ rm -rf "$LOCAL_PRISTINE" &&
292
+ git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
293
+ cd "$LOCAL_PRISTINE" &&
294
+ git checkout -b side &&
295
+ test_commit_bulk --id=s 33 &&
296
+
297
+ # Add novel commits to upstream
298
+ git checkout master &&
299
+ cd "$REPO" &&
300
+ test_commit m2 &&
301
+ test_commit m3 &&
302
+ git tag -d m2 m3
303
+ ) &&
304
+ git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_sed/repo" &&
305
+ git -C "$LOCAL_PRISTINE" config protocol.version 2
306
+ '
307
+
308
+ inconsistency () {
309
+ # Simulate that the server initially reports $2 as the ref
310
+ # corresponding to $1, and after that, $1 as the ref corresponding to
311
+ # $1. This corresponds to the real-life situation where the server's
312
+ # repository appears to change during negotiation, for example, when
313
+ # different servers in a load-balancing arrangement serve (stateless)
314
+ # RPCs during a single negotiation.
315
+ printf " s/%s/%s/" \
316
+ $( git -C " $REPO " rev-parse $1 | tr -d " \n" ) \
317
+ $( git -C " $REPO " rev-parse $2 | tr -d " \n" ) \
318
+ > " $HTTPD_ROOT_PATH /one-time-sed"
319
+ }
320
+
321
+ test_expect_success ' server is initially ahead - no ref in want' '
322
+ git -C "$REPO" config uploadpack.allowRefInWant false &&
323
+ rm -rf local &&
324
+ cp -r "$LOCAL_PRISTINE" local &&
325
+ inconsistency master 1234567890123456789012345678901234567890 &&
326
+ test_must_fail git -C local fetch 2>err &&
327
+ test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
328
+ '
329
+
330
+ test_expect_success ' server is initially ahead - ref in want' '
331
+ git -C "$REPO" config uploadpack.allowRefInWant true &&
332
+ rm -rf local &&
333
+ cp -r "$LOCAL_PRISTINE" local &&
334
+ inconsistency master 1234567890123456789012345678901234567890 &&
335
+ git -C local fetch &&
336
+
337
+ git -C "$REPO" rev-parse --verify master >expected &&
338
+ git -C local rev-parse --verify refs/remotes/origin/master >actual &&
339
+ test_cmp expected actual
340
+ '
341
+
342
+ test_expect_success ' server is initially behind - no ref in want' '
343
+ git -C "$REPO" config uploadpack.allowRefInWant false &&
344
+ rm -rf local &&
345
+ cp -r "$LOCAL_PRISTINE" local &&
346
+ inconsistency master "master^" &&
347
+ git -C local fetch &&
348
+
349
+ git -C "$REPO" rev-parse --verify "master^" >expected &&
350
+ git -C local rev-parse --verify refs/remotes/origin/master >actual &&
351
+ test_cmp expected actual
352
+ '
353
+
354
+ test_expect_success ' server is initially behind - ref in want' '
355
+ git -C "$REPO" config uploadpack.allowRefInWant true &&
356
+ rm -rf local &&
357
+ cp -r "$LOCAL_PRISTINE" local &&
358
+ inconsistency master "master^" &&
359
+ git -C local fetch &&
360
+
361
+ git -C "$REPO" rev-parse --verify "master" >expected &&
362
+ git -C local rev-parse --verify refs/remotes/origin/master >actual &&
363
+ test_cmp expected actual
364
+ '
365
+
366
+ test_expect_success ' server loses a ref - ref in want' '
367
+ git -C "$REPO" config uploadpack.allowRefInWant true &&
368
+ rm -rf local &&
369
+ cp -r "$LOCAL_PRISTINE" local &&
370
+ echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-sed" &&
371
+ test_must_fail git -C local fetch 2>err &&
372
+
373
+ test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
374
+ '
375
+
376
+ # DO NOT add non-httpd-specific tests here, because the last part of this
377
+ # test script is only executed when httpd is available and enabled.
378
+
375
379
test_done
0 commit comments