git check-ref-format: add options --allow-onelevel and --refspec-pattern
Also add tests of the new options. (Actually, one big reason to add the new options is to make it easy to test check_ref_format(), though the options should also be useful to other scripts.) Interpret the result of check_ref_format() based on which types of refnames are allowed. However, because check_ref_format() can only return a single value, one test case is still broken. Specifically, the case "git check-ref-format --onelevel '*'" incorrectly succeeds because check_ref_format() returns CHECK_REF_FORMAT_ONELEVEL for this refname even though the refname is also CHECK_REF_FORMAT_WILDCARD. The type of check that leads to this failure is used elsewhere in "real" code and could lead to bugs; it will be fixed over the next few commits. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f9b1a5b9b8
commit
e4ed6105ec
@ -5,25 +5,38 @@ test_description='Test git check-ref-format'
|
||||
. ./test-lib.sh
|
||||
|
||||
valid_ref() {
|
||||
test_expect_success "ref name '$1' is valid" \
|
||||
"git check-ref-format '$1'"
|
||||
if test "$#" = 1
|
||||
then
|
||||
test_expect_success "ref name '$1' is valid" \
|
||||
"git check-ref-format '$1'"
|
||||
else
|
||||
test_expect_success "ref name '$1' is valid with options $2" \
|
||||
"git check-ref-format $2 '$1'"
|
||||
fi
|
||||
}
|
||||
invalid_ref() {
|
||||
test_expect_success "ref name '$1' is not valid" \
|
||||
"test_must_fail git check-ref-format '$1'"
|
||||
if test "$#" = 1
|
||||
then
|
||||
test_expect_success "ref name '$1' is invalid" \
|
||||
"test_must_fail git check-ref-format '$1'"
|
||||
else
|
||||
test_expect_success "ref name '$1' is invalid with options $2" \
|
||||
"test_must_fail git check-ref-format $2 '$1'"
|
||||
fi
|
||||
}
|
||||
|
||||
invalid_ref ''
|
||||
invalid_ref '/'
|
||||
valid_ref 'heads/foo'
|
||||
invalid_ref 'foo'
|
||||
invalid_ref '/' --allow-onelevel
|
||||
valid_ref 'foo/bar/baz'
|
||||
valid_ref 'refs///heads/foo'
|
||||
invalid_ref 'heads/foo/'
|
||||
valid_ref '/heads/foo'
|
||||
valid_ref '///heads/foo'
|
||||
invalid_ref '/foo'
|
||||
invalid_ref './foo'
|
||||
invalid_ref './foo/bar'
|
||||
invalid_ref 'foo/./bar'
|
||||
invalid_ref 'foo/bar/.'
|
||||
invalid_ref '.refs/foo'
|
||||
invalid_ref 'heads/foo..bar'
|
||||
invalid_ref 'heads/foo?bar'
|
||||
@ -38,6 +51,67 @@ invalid_ref 'heads/foo\bar'
|
||||
invalid_ref "$(printf 'heads/foo\t')"
|
||||
invalid_ref "$(printf 'heads/foo\177')"
|
||||
valid_ref "$(printf 'heads/fu\303\237')"
|
||||
invalid_ref 'heads/*foo/bar' --refspec-pattern
|
||||
invalid_ref 'heads/foo*/bar' --refspec-pattern
|
||||
invalid_ref 'heads/f*o/bar' --refspec-pattern
|
||||
|
||||
ref='foo'
|
||||
invalid_ref "$ref"
|
||||
valid_ref "$ref" --allow-onelevel
|
||||
invalid_ref "$ref" --refspec-pattern
|
||||
valid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='foo/bar'
|
||||
valid_ref "$ref"
|
||||
valid_ref "$ref" --allow-onelevel
|
||||
valid_ref "$ref" --refspec-pattern
|
||||
valid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='foo/*'
|
||||
invalid_ref "$ref"
|
||||
invalid_ref "$ref" --allow-onelevel
|
||||
valid_ref "$ref" --refspec-pattern
|
||||
valid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='*/foo'
|
||||
invalid_ref "$ref"
|
||||
invalid_ref "$ref" --allow-onelevel
|
||||
valid_ref "$ref" --refspec-pattern
|
||||
valid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='foo/*/bar'
|
||||
invalid_ref "$ref"
|
||||
invalid_ref "$ref" --allow-onelevel
|
||||
valid_ref "$ref" --refspec-pattern
|
||||
valid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='*'
|
||||
invalid_ref "$ref"
|
||||
|
||||
#invalid_ref "$ref" --allow-onelevel
|
||||
test_expect_failure "ref name '$ref' is invalid with options --allow-onelevel" \
|
||||
"test_must_fail git check-ref-format --allow-onelevel '$ref'"
|
||||
|
||||
invalid_ref "$ref" --refspec-pattern
|
||||
valid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='foo/*/*'
|
||||
invalid_ref "$ref" --refspec-pattern
|
||||
invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='*/foo/*'
|
||||
invalid_ref "$ref" --refspec-pattern
|
||||
invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='*/*/foo'
|
||||
invalid_ref "$ref" --refspec-pattern
|
||||
invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
ref='/foo'
|
||||
invalid_ref "$ref"
|
||||
valid_ref "$ref" --allow-onelevel
|
||||
invalid_ref "$ref" --refspec-pattern
|
||||
valid_ref "$ref" '--refspec-pattern --allow-onelevel'
|
||||
|
||||
test_expect_success "check-ref-format --branch @{-1}" '
|
||||
T=$(git write-tree) &&
|
||||
|
Reference in New Issue
Block a user