Skip to content

Commit 8159f4a

Browse files
rsahlberggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3cc52d commit 8159f4a

File tree

3 files changed

+84
-74
lines changed

3 files changed

+84
-74
lines changed

t/t1400-update-ref.sh

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
136136
test_path_is_missing .git/refs/heads/ref-to-bad
137137
'
138138

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-
147139
test_expect_success '(not) create HEAD with old sha1' "
148140
test_must_fail git update-ref HEAD $A $B
149141
"
@@ -408,12 +400,6 @@ test_expect_success 'stdin fails create with no ref' '
408400
grep "fatal: create: missing <ref>" err
409401
'
410402

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-
417403
test_expect_success 'stdin fails create with no new value' '
418404
echo "create $a" >stdin &&
419405
test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -432,12 +418,6 @@ test_expect_success 'stdin fails update with no ref' '
432418
grep "fatal: update: missing <ref>" err
433419
'
434420

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-
441421
test_expect_success 'stdin fails update with no new value' '
442422
echo "update $a" >stdin &&
443423
test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -456,12 +436,6 @@ test_expect_success 'stdin fails delete with no ref' '
456436
grep "fatal: delete: missing <ref>" err
457437
'
458438

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-
465439
test_expect_success 'stdin fails delete with too many arguments' '
466440
echo "delete $a $m $m" >stdin &&
467441
test_must_fail git update-ref --stdin <stdin 2>err &&
@@ -734,12 +708,6 @@ test_expect_success 'stdin -z fails create with no ref' '
734708
grep "fatal: create: missing <ref>" err
735709
'
736710

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-
743711
test_expect_success 'stdin -z fails create with no new value' '
744712
printf $F "create $a" >stdin &&
745713
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' '
764732
grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
765733
'
766734

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-
773735
test_expect_success 'stdin -z emits warning with empty new value' '
774736
git update-ref $a $m &&
775737
printf $F "update $a" "" "" >stdin &&
@@ -802,12 +764,6 @@ test_expect_success 'stdin -z fails delete with no ref' '
802764
grep "fatal: delete: missing <ref>" err
803765
'
804766

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-
811767
test_expect_success 'stdin -z fails delete with no old value' '
812768
printf $F "delete $a" >stdin &&
813769
test_must_fail git update-ref -z --stdin <stdin 2>err &&

t/t1430-bad-ref-name.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -346,36 +346,6 @@ test_expect_success 'B: fail on invalid blob sha1' '
346346
'
347347
rm -f .git/objects/pack_* .git/objects/index_*
348348

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-
379349
cat >input <<INPUT_END
380350
commit TEMP_TAG
381351
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE

0 commit comments

Comments
 (0)