fast-import: add input format tests
Documentation/git-fast-import.txt says that git-fast-import is strict about it's input format. But committer/author field parsing is a bit loose. Invalid values can be unnoticed and written out to the commit, either with format-conforming input or with non-format-conforming one. Add one passing and one failing test for empty/absent committer name with well-formed input. And a failed test with unnoticed ill-formed input. Reported-by: SASAKI Suguru <sss.sonik@gmail.com> Signed-off-by: Dmitry Ivankov <divanorama@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dmitry Ivankov committed
Aug 11, 2011 at 16:21 UTC
4cedb78cb5eeb26d6dd47f866b51f061737616f2
1 file changed
+99
t/t9300-fast-import.sh
+99
@@ -324,6 +324,105 @@ test_expect_success \
324
test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
325
rm -f .git/TEMP_TAG
326
327
+git gc 2>/dev/null >/dev/null
328
+git prune 2>/dev/null >/dev/null
329
+
330
+cat >input <<INPUT_END
331
+commit refs/heads/empty-committer-1
332
+committer <> $GIT_COMMITTER_DATE
333
+data <<COMMIT
334
+empty commit
335
+COMMIT
336
+INPUT_END
337
+test_expect_success 'B: accept empty committer' '
338
+ git fast-import <input &&
339
+ out=$(git fsck) &&
340
+ echo "$out" &&
341
+ test -z "$out"
342
+'
343
+git update-ref -d refs/heads/empty-committer-1 || true
344
+
345
+git gc 2>/dev/null >/dev/null
346
+git prune 2>/dev/null >/dev/null
347
+
348
+cat >input <<INPUT_END
349
+commit refs/heads/empty-committer-2
350
+committer <a@b.com> $GIT_COMMITTER_DATE
351
+data <<COMMIT
352
+empty commit
353
+COMMIT
354
+INPUT_END
355
+test_expect_failure 'B: accept and fixup committer with no name' '
356
+ git fast-import <input &&
357
+ out=$(git fsck) &&
358
+ echo "$out" &&
359
+ test -z "$out"
360
+'
361
+git update-ref -d refs/heads/empty-committer-2 || true
362
+
363
+git gc 2>/dev/null >/dev/null
364
+git prune 2>/dev/null >/dev/null
365
+
366
+cat >input <<INPUT_END
367
+commit refs/heads/invalid-committer
368
+committer Name email> $GIT_COMMITTER_DATE
369
+data <<COMMIT
370
+empty commit
371
+COMMIT
372
+INPUT_END
373
+test_expect_failure 'B: fail on invalid committer (1)' '
374
+ test_must_fail git fast-import <input
375
+'
376
+git update-ref -d refs/heads/invalid-committer || true
377
+
378
+cat >input <<INPUT_END
379
+commit refs/heads/invalid-committer
380
+committer Name <e<mail> $GIT_COMMITTER_DATE
381
+data <<COMMIT
382
+empty commit
383
+COMMIT
384
+INPUT_END
385
+test_expect_failure 'B: fail on invalid committer (2)' '
386
+ test_must_fail git fast-import <input
387
+'
388
+git update-ref -d refs/heads/invalid-committer || true
389
+
390
+cat >input <<INPUT_END
391
+commit refs/heads/invalid-committer
392
+committer Name <email>> $GIT_COMMITTER_DATE
393
+data <<COMMIT
394
+empty commit
395
+COMMIT
396
+INPUT_END
397
+test_expect_failure 'B: fail on invalid committer (3)' '
398
+ test_must_fail git fast-import <input
399
+'
400
+git update-ref -d refs/heads/invalid-committer || true
401
+
402
+cat >input <<INPUT_END
403
+commit refs/heads/invalid-committer
404
+committer Name <email $GIT_COMMITTER_DATE
405
+data <<COMMIT
406
+empty commit
407
+COMMIT
408
+INPUT_END
409
+test_expect_failure 'B: fail on invalid committer (4)' '
410
+ test_must_fail git fast-import <input
411
+'
412
+git update-ref -d refs/heads/invalid-committer || true
413
+
414
+cat >input <<INPUT_END
415
+commit refs/heads/invalid-committer
416
+committer Name<email> $GIT_COMMITTER_DATE
417
+data <<COMMIT
418
+empty commit
419
+COMMIT
420
+INPUT_END
421
+test_expect_failure 'B: fail on invalid committer (5)' '
422
+ test_must_fail git fast-import <input
423
+'
424
+git update-ref -d refs/heads/invalid-committer || true
425
+
426
###
427
### series C
428
###