test: put tests for handling of bad ref names in one place
[git/git.git] / t / t1430-bad-ref-name.sh
CommitLineData
8159f4af
RS
1#!/bin/sh
2
3test_description='Test handling of ref names that check-ref-format rejects'
4. ./test-lib.sh
5
6test_expect_success setup '
7 test_commit one
8'
9
10test_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
25test_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
40test_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
48test_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
54test_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
60test_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
66test_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
72test_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
78test_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
84test_done