Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t1402-check-ref-format.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t1402-check-ref-format.sh` 223 lines ยท 6111 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='Test git check-ref-format' 4 5 . ./test-lib.sh 6 7 valid_ref() { 8 prereq= 9 case $1 in 10 [A-Z!]*) 11 prereq=$1 12 shift 13 esac 14 desc="ref name '$1' is valid${2:+ with options $2}" 15 test_expect_success $prereq "$desc" " 16 git check-ref-format $2 '$1' 17 " 18 } 19 invalid_ref() { 20 prereq= 21 case $1 in 22 [A-Z!]*) 23 prereq=$1 24 shift 25 esac 26 desc="ref name '$1' is invalid${2:+ with options $2}" 27 test_expect_success $prereq "$desc" " 28 test_must_fail git check-ref-format $2 '$1' 29 " 30 } 31 32 invalid_ref '' 33 invalid_ref !MINGW '/' 34 invalid_ref !MINGW '/' --allow-onelevel 35 invalid_ref !MINGW '/' --normalize 36 invalid_ref !MINGW '/' '--allow-onelevel --normalize' 37 valid_ref 'foo/bar/baz' 38 valid_ref 'foo/bar/baz' --normalize 39 invalid_ref 'refs///heads/foo' 40 valid_ref 'refs///heads/foo' --normalize 41 invalid_ref 'heads/foo/' 42 invalid_ref !MINGW '/heads/foo' 43 valid_ref !MINGW '/heads/foo' --normalize 44 invalid_ref '///heads/foo' 45 valid_ref '///heads/foo' --normalize 46 invalid_ref './foo' 47 invalid_ref './foo/bar' 48 invalid_ref 'foo/./bar' 49 invalid_ref 'foo/bar/.' 50 invalid_ref '.refs/foo' 51 invalid_ref 'refs/heads/foo.' 52 for c in '?' '~' '^' ':' '*' '[' ' ' '\' '..' 53 do 54 invalid_ref "heads/foo${c}bar" 55 done 56 valid_ref 'foo./bar' 57 invalid_ref 'heads/foo.lock' 58 invalid_ref 'heads///foo.lock' 59 invalid_ref 'foo.lock/bar' 60 invalid_ref 'foo.lock///bar' 61 valid_ref 'heads/foo@bar' 62 valid_ref 'refs/@' 63 invalid_ref '@' --allow-onelevel 64 invalid_ref 'heads/v@{ation' 65 invalid_ref "$(printf 'heads/foo\t')" 66 invalid_ref "$(printf 'heads/foo\177')" 67 valid_ref "$(printf 'heads/fu\303\237')" 68 valid_ref 'heads/*foo/bar' --refspec-pattern 69 valid_ref 'heads/foo*/bar' --refspec-pattern 70 valid_ref 'heads/f*o/bar' --refspec-pattern 71 invalid_ref 'heads/f*o*/bar' --refspec-pattern 72 invalid_ref 'heads/foo*/bar*' --refspec-pattern 73 74 ref='foo' 75 invalid_ref "$ref" 76 valid_ref "$ref" --allow-onelevel 77 invalid_ref "$ref" '--allow-onelevel --no-allow-onelevel' 78 valid_ref "$ref" '--no-allow-onelevel --allow-onelevel' 79 invalid_ref "$ref" --refspec-pattern 80 valid_ref "$ref" '--refspec-pattern --allow-onelevel' 81 invalid_ref "$ref" --normalize 82 valid_ref "$ref" '--allow-onelevel --normalize' 83 84 ref='foo/bar' 85 valid_ref "$ref" 86 valid_ref "$ref" --allow-onelevel 87 valid_ref "$ref" --refspec-pattern 88 valid_ref "$ref" '--refspec-pattern --allow-onelevel' 89 valid_ref "$ref" --normalize 90 91 ref='foo/*' 92 invalid_ref "$ref" 93 invalid_ref "$ref" --allow-onelevel 94 valid_ref "$ref" --refspec-pattern 95 valid_ref "$ref" '--refspec-pattern --allow-onelevel' 96 97 ref='*/foo' 98 invalid_ref "$ref" 99 invalid_ref "$ref" --allow-onelevel 100 valid_ref "$ref" --refspec-pattern 101 valid_ref "$ref" '--refspec-pattern --allow-onelevel' 102 invalid_ref "$ref" --normalize 103 valid_ref "$ref" '--refspec-pattern --normalize' 104 105 ref='foo/*/bar' 106 invalid_ref "$ref" 107 invalid_ref "$ref" --allow-onelevel 108 valid_ref "$ref" --refspec-pattern 109 valid_ref "$ref" '--refspec-pattern --allow-onelevel' 110 111 ref='*' 112 invalid_ref "$ref" 113 invalid_ref "$ref" --allow-onelevel 114 invalid_ref "$ref" --refspec-pattern 115 valid_ref "$ref" '--refspec-pattern --allow-onelevel' 116 117 ref='foo/*/*' 118 invalid_ref "$ref" --refspec-pattern 119 invalid_ref "$ref" '--refspec-pattern --allow-onelevel' 120 121 ref='*/foo/*' 122 invalid_ref "$ref" --refspec-pattern 123 invalid_ref "$ref" '--refspec-pattern --allow-onelevel' 124 125 ref='*/*/foo' 126 invalid_ref "$ref" --refspec-pattern 127 invalid_ref "$ref" '--refspec-pattern --allow-onelevel' 128 129 ref='/foo' 130 invalid_ref !MINGW "$ref" 131 invalid_ref !MINGW "$ref" --allow-onelevel 132 invalid_ref !MINGW "$ref" --refspec-pattern 133 invalid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel' 134 invalid_ref !MINGW "$ref" --normalize 135 valid_ref !MINGW "$ref" '--allow-onelevel --normalize' 136 invalid_ref !MINGW "$ref" '--refspec-pattern --normalize' 137 valid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize' 138 139 test_expect_success "check-ref-format --branch @{-1}" ' 140 T=$(git write-tree) && 141 sha1=$(echo A | git commit-tree $T) && 142 git update-ref refs/heads/main $sha1 && 143 git update-ref refs/remotes/origin/main $sha1 && 144 git checkout main && 145 git checkout origin/main && 146 git checkout main && 147 refname=$(git check-ref-format --branch @{-1}) && 148 test "$refname" = "$sha1" && 149 refname2=$(git check-ref-format --branch @{-2}) && 150 test "$refname2" = main' 151 152 test_expect_success 'check-ref-format --branch -nain' ' 153 test_must_fail git check-ref-format --branch -nain >actual && 154 test_must_be_empty actual 155 ' 156 157 test_expect_success 'check-ref-format --branch from subdir' ' 158 mkdir subdir && 159 160 T=$(git write-tree) && 161 sha1=$(echo A | git commit-tree $T) && 162 git update-ref refs/heads/main $sha1 && 163 git update-ref refs/remotes/origin/main $sha1 && 164 git checkout main && 165 git checkout origin/main && 166 git checkout main && 167 refname=$( 168 cd subdir && 169 git check-ref-format --branch @{-1} 170 ) && 171 test "$refname" = "$sha1" 172 ' 173 174 test_expect_success 'check-ref-format --branch @{-1} from non-repo' ' 175 nongit test_must_fail git check-ref-format --branch @{-1} >actual && 176 test_must_be_empty actual 177 ' 178 179 test_expect_success 'check-ref-format --branch main from non-repo' ' 180 echo main >expect && 181 nongit git check-ref-format --branch main >actual && 182 test_cmp expect actual 183 ' 184 185 valid_ref_normalized() { 186 prereq= 187 case $1 in 188 [A-Z!]*) 189 prereq=$1 190 shift 191 esac 192 test_expect_success $prereq "ref name '$1' simplifies to '$2'" " 193 refname=\$(git check-ref-format --normalize '$1') && 194 test \"\$refname\" = '$2' 195 " 196 } 197 invalid_ref_normalized() { 198 prereq= 199 case $1 in 200 [A-Z!]*) 201 prereq=$1 202 shift 203 esac 204 test_expect_success $prereq "check-ref-format --normalize rejects '$1'" " 205 test_must_fail git check-ref-format --normalize '$1' 206 " 207 } 208 209 valid_ref_normalized 'heads/foo' 'heads/foo' 210 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo' 211 valid_ref_normalized !MINGW '/heads/foo' 'heads/foo' 212 valid_ref_normalized '///heads/foo' 'heads/foo' 213 invalid_ref_normalized 'foo' 214 invalid_ref_normalized !MINGW '/foo' 215 invalid_ref_normalized 'heads/foo/../bar' 216 invalid_ref_normalized 'heads/./foo' 217 invalid_ref_normalized 'heads\foo' 218 invalid_ref_normalized 'heads/foo.lock' 219 invalid_ref_normalized 'heads///foo.lock' 220 invalid_ref_normalized 'foo.lock/bar' 221 invalid_ref_normalized 'foo.lock///bar' 222 223 test_done