-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fsck: add ref name check for files backend
The git-fsck(1) only implicitly checks the reference, it does not fully check refs with bad format name such as standalone "@". However, a file ending with ".lock" should not be marked as having a bad ref name. It is expected that concurrent writers may have such lock files. We currently ignore this situation. But for bare ".lock" file, we will report it as error. In order to provide such checks, add a new fsck message id "badRefName" with default ERROR type. Use existing "check_refname_format" to explicit check the ref name. And add a new unit test to verify the functionality. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: shejialuo <shejialuo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/sh | ||
|
||
test_description='Test reffiles backend consistency check' | ||
|
||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | ||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | ||
GIT_TEST_DEFAULT_REF_FORMAT=files | ||
export GIT_TEST_DEFAULT_REF_FORMAT | ||
TEST_PASSES_SANITIZE_LEAK=true | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success 'ref name should be checked' ' | ||
test_when_finished "rm -rf repo" && | ||
git init repo && | ||
branch_dir_prefix=.git/refs/heads && | ||
tag_dir_prefix=.git/refs/tags && | ||
cd repo && | ||
git commit --allow-empty -m initial && | ||
git checkout -b branch-1 && | ||
git tag tag-1 && | ||
git commit --allow-empty -m second && | ||
git checkout -b branch-2 && | ||
git tag tag-2 && | ||
git tag multi_hierarchy/tag-2 && | ||
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && | ||
test_must_fail git refs verify 2>err && | ||
cat >expect <<-EOF && | ||
error: refs/heads/.branch-1: badRefName: invalid refname format | ||
EOF | ||
rm $branch_dir_prefix/.branch-1 && | ||
test_cmp expect err && | ||
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && | ||
test_must_fail git refs verify 2>err && | ||
cat >expect <<-EOF && | ||
error: refs/heads/@: badRefName: invalid refname format | ||
EOF | ||
rm $branch_dir_prefix/@ && | ||
test_cmp expect err && | ||
cp $tag_dir_prefix/multi_hierarchy/tag-2 $tag_dir_prefix/multi_hierarchy/@ && | ||
test_must_fail git refs verify 2>err && | ||
cat >expect <<-EOF && | ||
error: refs/tags/multi_hierarchy/@: badRefName: invalid refname format | ||
EOF | ||
rm $tag_dir_prefix/multi_hierarchy/@ && | ||
test_cmp expect err && | ||
cp $tag_dir_prefix/tag-1 $tag_dir_prefix/tag-1.lock && | ||
git refs verify 2>err && | ||
rm $tag_dir_prefix/tag-1.lock && | ||
test_must_be_empty err && | ||
cp $tag_dir_prefix/tag-1 $tag_dir_prefix/.lock && | ||
test_must_fail git refs verify 2>err && | ||
cat >expect <<-EOF && | ||
error: refs/tags/.lock: badRefName: invalid refname format | ||
EOF | ||
rm $tag_dir_prefix/.lock && | ||
test_cmp expect err | ||
' | ||
|
||
test_expect_success 'ref name check should be adapted into fsck messages' ' | ||
test_when_finished "rm -rf repo" && | ||
git init repo && | ||
branch_dir_prefix=.git/refs/heads && | ||
tag_dir_prefix=.git/refs/tags && | ||
cd repo && | ||
git commit --allow-empty -m initial && | ||
git checkout -b branch-1 && | ||
git tag tag-1 && | ||
git commit --allow-empty -m second && | ||
git checkout -b branch-2 && | ||
git tag tag-2 && | ||
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && | ||
git -c fsck.badRefName=warn refs verify 2>err && | ||
cat >expect <<-EOF && | ||
warning: refs/heads/.branch-1: badRefName: invalid refname format | ||
EOF | ||
rm $branch_dir_prefix/.branch-1 && | ||
test_cmp expect err && | ||
cp $branch_dir_prefix/branch-1 $branch_dir_prefix/@ && | ||
git -c fsck.badRefName=ignore refs verify 2>err && | ||
test_must_be_empty err | ||
' | ||
|
||
test_done |