Fourth batch
[gitweb.git] / t / t1402-check-ref-format.sh
index 4bc7141226c802ca049a76e978b6196f9e9fd7ff..98e4a8613ba8ab4aebe99360e89c21be2ce3473d 100755 (executable)
@@ -7,7 +7,7 @@ test_description='Test git check-ref-format'
 valid_ref() {
        prereq=
        case $1 in
-       [A-Z]*)
+       [A-Z!]*)
                prereq=$1
                shift
        esac
@@ -19,7 +19,7 @@ valid_ref() {
 invalid_ref() {
        prereq=
        case $1 in
-       [A-Z]*)
+       [A-Z!]*)
                prereq=$1
                shift
        esac
@@ -30,17 +30,17 @@ invalid_ref() {
 }
 
 invalid_ref ''
-invalid_ref NOT_MINGW '/'
-invalid_ref NOT_MINGW '/' --allow-onelevel
-invalid_ref NOT_MINGW '/' --normalize
-invalid_ref NOT_MINGW '/' '--allow-onelevel --normalize'
+invalid_ref !MINGW '/'
+invalid_ref !MINGW '/' --allow-onelevel
+invalid_ref !MINGW '/' --normalize
+invalid_ref !MINGW '/' '--allow-onelevel --normalize'
 valid_ref 'foo/bar/baz'
 valid_ref 'foo/bar/baz' --normalize
 invalid_ref 'refs///heads/foo'
 valid_ref 'refs///heads/foo' --normalize
 invalid_ref 'heads/foo/'
-invalid_ref NOT_MINGW '/heads/foo'
-valid_ref NOT_MINGW '/heads/foo' --normalize
+invalid_ref !MINGW '/heads/foo'
+valid_ref !MINGW '/heads/foo' --normalize
 invalid_ref '///heads/foo'
 valid_ref '///heads/foo' --normalize
 invalid_ref './foo'
@@ -62,9 +62,11 @@ 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
+valid_ref 'heads/*foo/bar' --refspec-pattern
+valid_ref 'heads/foo*/bar' --refspec-pattern
+valid_ref 'heads/f*o/bar' --refspec-pattern
+invalid_ref 'heads/f*o*/bar' --refspec-pattern
+invalid_ref 'heads/foo*/bar*' --refspec-pattern
 
 ref='foo'
 invalid_ref "$ref"
@@ -120,14 +122,14 @@ invalid_ref "$ref" --refspec-pattern
 invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
 
 ref='/foo'
-invalid_ref NOT_MINGW "$ref"
-invalid_ref NOT_MINGW "$ref" --allow-onelevel
-invalid_ref NOT_MINGW "$ref" --refspec-pattern
-invalid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel'
-invalid_ref NOT_MINGW "$ref" --normalize
-valid_ref NOT_MINGW "$ref" '--allow-onelevel --normalize'
-invalid_ref NOT_MINGW "$ref" '--refspec-pattern --normalize'
-valid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize'
+invalid_ref !MINGW "$ref"
+invalid_ref !MINGW "$ref" --allow-onelevel
+invalid_ref !MINGW "$ref" --refspec-pattern
+invalid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel'
+invalid_ref !MINGW "$ref" --normalize
+valid_ref !MINGW "$ref" '--allow-onelevel --normalize'
+invalid_ref !MINGW "$ref" '--refspec-pattern --normalize'
+valid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize'
 
 test_expect_success "check-ref-format --branch @{-1}" '
        T=$(git write-tree) &&
@@ -142,6 +144,11 @@ test_expect_success "check-ref-format --branch @{-1}" '
        refname2=$(git check-ref-format --branch @{-2}) &&
        test "$refname2" = master'
 
+test_expect_success 'check-ref-format --branch -naster' '
+       test_must_fail git check-ref-format --branch -naster >actual &&
+       test_must_be_empty actual
+'
+
 test_expect_success 'check-ref-format --branch from subdir' '
        mkdir subdir &&
 
@@ -159,10 +166,21 @@ test_expect_success 'check-ref-format --branch from subdir' '
        test "$refname" = "$sha1"
 '
 
+test_expect_success 'check-ref-format --branch @{-1} from non-repo' '
+       nongit test_must_fail git check-ref-format --branch @{-1} >actual &&
+       test_must_be_empty actual
+'
+
+test_expect_success 'check-ref-format --branch master from non-repo' '
+       echo master >expect &&
+       nongit git check-ref-format --branch master >actual &&
+       test_cmp expect actual
+'
+
 valid_ref_normalized() {
        prereq=
        case $1 in
-       [A-Z]*)
+       [A-Z!]*)
                prereq=$1
                shift
        esac
@@ -174,7 +192,7 @@ valid_ref_normalized() {
 invalid_ref_normalized() {
        prereq=
        case $1 in
-       [A-Z]*)
+       [A-Z!]*)
                prereq=$1
                shift
        esac
@@ -185,10 +203,10 @@ invalid_ref_normalized() {
 
 valid_ref_normalized 'heads/foo' 'heads/foo'
 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
-valid_ref_normalized NOT_MINGW '/heads/foo' 'heads/foo'
+valid_ref_normalized !MINGW '/heads/foo' 'heads/foo'
 valid_ref_normalized '///heads/foo' 'heads/foo'
 invalid_ref_normalized 'foo'
-invalid_ref_normalized NOT_MINGW '/foo'
+invalid_ref_normalized !MINGW '/foo'
 invalid_ref_normalized 'heads/foo/../bar'
 invalid_ref_normalized 'heads/./foo'
 invalid_ref_normalized 'heads\foo'