Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t0602-reffiles-fsck.sh
blob71a4d1a5ae4bab3dcca3a8ecc1060cb2f360ab30
1 #!/bin/sh
3 test_description='Test reffiles backend consistency check'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 GIT_TEST_DEFAULT_REF_FORMAT=files
8 export GIT_TEST_DEFAULT_REF_FORMAT
9 TEST_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
13 test_expect_success 'ref name should be checked' '
14 test_when_finished "rm -rf repo" &&
15 git init repo &&
16 branch_dir_prefix=.git/refs/heads &&
17 tag_dir_prefix=.git/refs/tags &&
18 cd repo &&
20 git commit --allow-empty -m initial &&
21 git checkout -b branch-1 &&
22 git tag tag-1 &&
23 git commit --allow-empty -m second &&
24 git checkout -b branch-2 &&
25 git tag tag-2 &&
26 git tag multi_hierarchy/tag-2 &&
28 cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
29 test_must_fail git refs verify 2>err &&
30 cat >expect <<-EOF &&
31 error: refs/heads/.branch-1: badRefName: invalid refname format
32 EOF
33 rm $branch_dir_prefix/.branch-1 &&
34 test_cmp expect err &&
36 cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ &&
37 test_must_fail git refs verify 2>err &&
38 cat >expect <<-EOF &&
39 error: refs/heads/@: badRefName: invalid refname format
40 EOF
41 rm $branch_dir_prefix/@ &&
42 test_cmp expect err &&
44 cp $tag_dir_prefix/multi_hierarchy/tag-2 $tag_dir_prefix/multi_hierarchy/@ &&
45 test_must_fail git refs verify 2>err &&
46 cat >expect <<-EOF &&
47 error: refs/tags/multi_hierarchy/@: badRefName: invalid refname format
48 EOF
49 rm $tag_dir_prefix/multi_hierarchy/@ &&
50 test_cmp expect err &&
52 cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock &&
53 git refs verify 2>err &&
54 rm $tag_dir_prefix/tag-1.lock &&
55 test_must_be_empty err &&
57 cp $tag_dir_prefix/tag-1 $tag_dir_prefix/.lock &&
58 test_must_fail git refs verify 2>err &&
59 cat >expect <<-EOF &&
60 error: refs/tags/.lock: badRefName: invalid refname format
61 EOF
62 rm $tag_dir_prefix/.lock &&
63 test_cmp expect err
66 test_expect_success 'ref name check should be adapted into fsck messages' '
67 test_when_finished "rm -rf repo" &&
68 git init repo &&
69 branch_dir_prefix=.git/refs/heads &&
70 tag_dir_prefix=.git/refs/tags &&
71 cd repo &&
72 git commit --allow-empty -m initial &&
73 git checkout -b branch-1 &&
74 git tag tag-1 &&
75 git commit --allow-empty -m second &&
76 git checkout -b branch-2 &&
77 git tag tag-2 &&
79 cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 &&
80 git -c fsck.badRefName=warn refs verify 2>err &&
81 cat >expect <<-EOF &&
82 warning: refs/heads/.branch-1: badRefName: invalid refname format
83 EOF
84 rm $branch_dir_prefix/.branch-1 &&
85 test_cmp expect err &&
87 cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ &&
88 git -c fsck.badRefName=ignore refs verify 2>err &&
89 test_must_be_empty err
92 test_done