test: put tests for handling of bad ref names in one place

There's no straightforward way to grep for all tests dealing with invalid refs. Put them in a single test script so it is easy to see what functionality has not been exercised with bad ref names yet. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ronnie Sahlberg committed Sep 25, 2014 at 15:02 UTC 8159f4af7d21e106ed04d69c428b395701b94205
3 files changed +84 -74
t/t1400-update-ref.sh
-44
@@ -136,14 +136,6 @@ test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
136 test_path_is_missing .git/refs/heads/ref-to-bad
137 '
138
139 -test_expect_success 'update-ref --no-deref -d can delete reference to broken name' '
140 - git symbolic-ref refs/heads/badname refs/heads/broken...ref &&
141 - test_when_finished "rm -f .git/refs/heads/badname" &&
142 - test_path_is_file .git/refs/heads/badname &&
143 - git update-ref --no-deref -d refs/heads/badname &&
144 - test_path_is_missing .git/refs/heads/badname
145 -'
146 -
139 test_expect_success '(not) create HEAD with old sha1' "
140 test_must_fail git update-ref HEAD $A $B
141 "
@@ -408,12 +400,6 @@ test_expect_success 'stdin fails create with no ref' '
400 grep "fatal: create: missing <ref>" err
401 '
402
411 -test_expect_success 'stdin fails create with bad ref name' '
412 - echo "create ~a $m" >stdin &&
413 - test_must_fail git update-ref --stdin <stdin 2>err &&
414 - grep "fatal: invalid ref format: ~a" err
415 -'
416 -
403 test_expect_success 'stdin fails create with no new value' '
404 echo "create $a" >stdin &&
405 test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -432,12 +418,6 @@ test_expect_success 'stdin fails update with no ref' '
418 grep "fatal: update: missing <ref>" err
419 '
420
435 -test_expect_success 'stdin fails update with bad ref name' '
436 - echo "update ~a $m" >stdin &&
437 - test_must_fail git update-ref --stdin <stdin 2>err &&
438 - grep "fatal: invalid ref format: ~a" err
439 -'
440 -
421 test_expect_success 'stdin fails update with no new value' '
422 echo "update $a" >stdin &&
423 test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -456,12 +436,6 @@ test_expect_success 'stdin fails delete with no ref' '
436 grep "fatal: delete: missing <ref>" err
437 '
438
459 -test_expect_success 'stdin fails delete with bad ref name' '
460 - echo "delete ~a $m" >stdin &&
461 - test_must_fail git update-ref --stdin <stdin 2>err &&
462 - grep "fatal: invalid ref format: ~a" err
463 -'
464 -
439 test_expect_success 'stdin fails delete with too many arguments' '
440 echo "delete $a $m $m" >stdin &&
441 test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -734,12 +708,6 @@ test_expect_success 'stdin -z fails create with no ref' '
708 grep "fatal: create: missing <ref>" err
709 '
710
737 -test_expect_success 'stdin -z fails create with bad ref name' '
738 - printf $F "create ~a " "$m" >stdin &&
739 - test_must_fail git update-ref -z --stdin <stdin 2>err &&
740 - grep "fatal: invalid ref format: ~a " err
741 -'
742 -
711 test_expect_success 'stdin -z fails create with no new value' '
712 printf $F "create $a" >stdin &&
713 test_must_fail git update-ref -z --stdin <stdin 2>err &&
@@ -764,12 +732,6 @@ test_expect_success 'stdin -z fails update with too few args' '
732 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
733 '
734
767 -test_expect_success 'stdin -z fails update with bad ref name' '
768 - printf $F "update ~a" "$m" "" >stdin &&
769 - test_must_fail git update-ref -z --stdin <stdin 2>err &&
770 - grep "fatal: invalid ref format: ~a" err
771 -'
772 -
735 test_expect_success 'stdin -z emits warning with empty new value' '
736 git update-ref $a $m &&
737 printf $F "update $a" "" "" >stdin &&
@@ -802,12 +764,6 @@ test_expect_success 'stdin -z fails delete with no ref' '
764 grep "fatal: delete: missing <ref>" err
765 '
766
805 -test_expect_success 'stdin -z fails delete with bad ref name' '
806 - printf $F "delete ~a" "$m" >stdin &&
807 - test_must_fail git update-ref -z --stdin <stdin 2>err &&
808 - grep "fatal: invalid ref format: ~a" err
809 -'
810 -
767 test_expect_success 'stdin -z fails delete with no old value' '
768 printf $F "delete $a" >stdin &&
769 test_must_fail git update-ref -z --stdin <stdin 2>err &&
t/t1430-bad-ref-name.sh new
+84
@@ -0,0 +1,84 @@
1 +#!/bin/sh
2 +
3 +test_description='Test handling of ref names that check-ref-format rejects'
4 +. ./test-lib.sh
5 +
6 +test_expect_success setup '
7 + test_commit one
8 +'
9 +
10 +test_expect_success 'fast-import: fail on invalid branch name ".badbranchname"' '
11 + test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
12 + cat >input <<-INPUT_END &&
13 + commit .badbranchname
14 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
15 + data <<COMMIT
16 + corrupt
17 + COMMIT
18 +
19 + from refs/heads/master
20 +
21 + INPUT_END
22 + test_must_fail git fast-import <input
23 +'
24 +
25 +test_expect_success 'fast-import: fail on invalid branch name "bad[branch]name"' '
26 + test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
27 + cat >input <<-INPUT_END &&
28 + commit bad[branch]name
29 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
30 + data <<COMMIT
31 + corrupt
32 + COMMIT
33 +
34 + from refs/heads/master
35 +
36 + INPUT_END
37 + test_must_fail git fast-import <input
38 +'
39 +
40 +test_expect_success 'update-ref --no-deref -d can delete reference to broken name' '
41 + git symbolic-ref refs/heads/badname refs/heads/broken...ref &&
42 + test_when_finished "rm -f .git/refs/heads/badname" &&
43 + test_path_is_file .git/refs/heads/badname &&
44 + git update-ref --no-deref -d refs/heads/badname &&
45 + test_path_is_missing .git/refs/heads/badname
46 +'
47 +
48 +test_expect_success 'update-ref --stdin fails create with bad ref name' '
49 + echo "create ~a refs/heads/master" >stdin &&
50 + test_must_fail git update-ref --stdin <stdin 2>err &&
51 + grep "fatal: invalid ref format: ~a" err
52 +'
53 +
54 +test_expect_success 'update-ref --stdin fails update with bad ref name' '
55 + echo "update ~a refs/heads/master" >stdin &&
56 + test_must_fail git update-ref --stdin <stdin 2>err &&
57 + grep "fatal: invalid ref format: ~a" err
58 +'
59 +
60 +test_expect_success 'update-ref --stdin fails delete with bad ref name' '
61 + echo "delete ~a refs/heads/master" >stdin &&
62 + test_must_fail git update-ref --stdin <stdin 2>err &&
63 + grep "fatal: invalid ref format: ~a" err
64 +'
65 +
66 +test_expect_success 'update-ref --stdin -z fails create with bad ref name' '
67 + printf "%s\0" "create ~a " refs/heads/master >stdin &&
68 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
69 + grep "fatal: invalid ref format: ~a " err
70 +'
71 +
72 +test_expect_success 'update-ref --stdin -z fails update with bad ref name' '
73 + printf "%s\0" "update ~a" refs/heads/master "" >stdin &&
74 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
75 + grep "fatal: invalid ref format: ~a" err
76 +'
77 +
78 +test_expect_success 'update-ref --stdin -z fails delete with bad ref name' '
79 + printf "%s\0" "delete ~a" refs/heads/master >stdin &&
80 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
81 + grep "fatal: invalid ref format: ~a" err
82 +'
83 +
84 +test_done
t/t9300-fast-import.sh
-30
@@ -346,36 +346,6 @@ test_expect_success 'B: fail on invalid blob sha1' '
346 '
347 rm -f .git/objects/pack_* .git/objects/index_*
348
349 -cat >input <<INPUT_END
350 -commit .badbranchname
351 -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
352 -data <<COMMIT
353 -corrupt
354 -COMMIT
355 -
356 -from refs/heads/master
357 -
358 -INPUT_END
359 -test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
360 - test_must_fail git fast-import <input
361 -'
362 -rm -f .git/objects/pack_* .git/objects/index_*
363 -
364 -cat >input <<INPUT_END
365 -commit bad[branch]name
366 -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
367 -data <<COMMIT
368 -corrupt
369 -COMMIT
370 -
371 -from refs/heads/master
372 -
373 -INPUT_END
374 -test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
375 - test_must_fail git fast-import <input
376 -'
377 -rm -f .git/objects/pack_* .git/objects/index_*
378 -
349 cat >input <<INPUT_END
350 commit TEMP_TAG
351 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE