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/t1401-symbolic-ref.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 / t1401-symbolic-ref.sh` 237 lines · 7170 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='basic symbolic-ref tests' 4 5 . ./test-lib.sh 6 7 # If the tests munging HEAD fail, they can break detection of 8 # the git repo, meaning that further tests will operate on 9 # the surrounding git repo instead of the trash directory. 10 reset_to_sane() { 11 rm -rf .git && 12 "$TAR" xf .git.tar 13 } 14 15 test_expect_success 'setup' ' 16 git symbolic-ref HEAD refs/heads/foo && 17 test_commit file && 18 "$TAR" cf .git.tar .git 19 ' 20 21 test_expect_success 'symbolic-ref read/write roundtrip' ' 22 git symbolic-ref HEAD refs/heads/read-write-roundtrip && 23 echo refs/heads/read-write-roundtrip >expect && 24 git symbolic-ref HEAD >actual && 25 test_cmp expect actual 26 ' 27 28 test_expect_success 'symbolic-ref refuses non-ref for HEAD' ' 29 test_must_fail git symbolic-ref HEAD foo 30 ' 31 32 reset_to_sane 33 34 test_expect_success 'symbolic-ref refuses bare sha1' ' 35 rev=$(git rev-parse HEAD) && 36 test_must_fail git symbolic-ref HEAD "$rev" 37 ' 38 39 reset_to_sane 40 41 test_expect_success 'symbolic-ref reports a non-symbolic ref' ' 42 test_must_fail git symbolic-ref refs/heads/foo >out 2>err && 43 test_must_be_empty out && 44 test_grep "is not a symbolic ref" err 45 ' 46 47 test_expect_success 'symbolic-ref -q is silent on a non-symbolic ref' ' 48 test_must_fail git symbolic-ref -q refs/heads/foo >out 2>err && 49 test_must_be_empty out && 50 test_must_be_empty err 51 ' 52 53 test_expect_success 'HEAD cannot be removed' ' 54 test_must_fail git symbolic-ref -d HEAD 55 ' 56 57 reset_to_sane 58 59 test_expect_success 'symbolic-ref can be deleted' ' 60 git symbolic-ref NOTHEAD refs/heads/foo && 61 git symbolic-ref -d NOTHEAD && 62 git rev-parse refs/heads/foo && 63 test_must_fail git symbolic-ref NOTHEAD 64 ' 65 reset_to_sane 66 67 test_expect_success 'symbolic-ref can delete dangling symref' ' 68 git symbolic-ref NOTHEAD refs/heads/missing && 69 git symbolic-ref -d NOTHEAD && 70 test_must_fail git rev-parse refs/heads/missing && 71 test_must_fail git symbolic-ref NOTHEAD 72 ' 73 reset_to_sane 74 75 test_expect_success 'symbolic-ref fails to delete missing FOO' ' 76 echo "fatal: Cannot delete FOO, not a symbolic ref" >expect && 77 test_must_fail git symbolic-ref -d FOO >actual 2>&1 && 78 test_cmp expect actual 79 ' 80 reset_to_sane 81 82 test_expect_success 'symbolic-ref fails to delete real ref' ' 83 echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect && 84 test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 && 85 git rev-parse --verify refs/heads/foo && 86 test_cmp expect actual 87 ' 88 reset_to_sane 89 90 test_expect_success 'create large ref name' ' 91 # make 256+ character ref; some systems may not handle that, 92 # so be gentle 93 long=`0123456789abcdef` && 94 long=$long/$long/$long/$long && 95 long=$long/$long/$long/$long && 96 long_ref=refs/heads/$long && 97 tree=$(git write-tree) && 98 commit=$(echo foo | git commit-tree $tree) && 99 if git update-ref $long_ref $commit; then 100 test_set_prereq LONG_REF 101 else 102 echo >&2 "long refs not supported" 103 fi 104 ' 105 106 test_expect_success LONG_REF 'symbolic-ref can point to large ref name' ' 107 git symbolic-ref HEAD $long_ref && 108 echo $long_ref >expect && 109 git symbolic-ref HEAD >actual && 110 test_cmp expect actual 111 ' 112 113 test_expect_success LONG_REF 'we can parse long symbolic ref' ' 114 echo $commit >expect && 115 git rev-parse --verify HEAD >actual && 116 test_cmp expect actual 117 ' 118 119 test_expect_success 'symbolic-ref reports failure in exit code' ' 120 # Create d/f conflict to simulate failure. 121 test_must_fail git symbolic-ref refs/heads refs/heads/foo 122 ' 123 124 test_expect_success 'symbolic-ref writes reflog entry' ' 125 git checkout -b log1 && 126 test_commit one && 127 git checkout -b log2 && 128 test_commit two && 129 git checkout --orphan orphan && 130 git symbolic-ref -m create HEAD refs/heads/log1 && 131 git symbolic-ref -m update HEAD refs/heads/log2 && 132 cat >expect <<-\EOF && 133 update 134 create 135 EOF 136 git log --format=%gs -g -2 >actual && 137 test_cmp expect actual 138 ' 139 140 test_expect_success 'symbolic-ref does not create ref d/f conflicts' ' 141 git checkout -b df && 142 test_commit df && 143 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df && 144 git pack-refs --all --prune && 145 test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df 146 ' 147 148 test_expect_success 'symbolic-ref can overwrite pointer to invalid name' ' 149 test_when_finished reset_to_sane && 150 head=$(git rev-parse HEAD) && 151 git symbolic-ref HEAD refs/heads/outer && 152 test_when_finished "git update-ref -d refs/heads/outer/inner" && 153 git update-ref refs/heads/outer/inner $head && 154 git symbolic-ref HEAD refs/heads/unrelated 155 ' 156 157 test_expect_success 'symbolic-ref can resolve d/f name (EISDIR)' ' 158 test_when_finished reset_to_sane && 159 head=$(git rev-parse HEAD) && 160 git symbolic-ref HEAD refs/heads/outer/inner && 161 test_when_finished "git update-ref -d refs/heads/outer" && 162 git update-ref refs/heads/outer $head && 163 echo refs/heads/outer/inner >expect && 164 git symbolic-ref HEAD >actual && 165 test_cmp expect actual 166 ' 167 168 test_expect_success 'symbolic-ref can resolve d/f name (ENOTDIR)' ' 169 test_when_finished reset_to_sane && 170 head=$(git rev-parse HEAD) && 171 git symbolic-ref HEAD refs/heads/outer && 172 test_when_finished "git update-ref -d refs/heads/outer/inner" && 173 git update-ref refs/heads/outer/inner $head && 174 echo refs/heads/outer >expect && 175 git symbolic-ref HEAD >actual && 176 test_cmp expect actual 177 ' 178 179 test_expect_success 'symbolic-ref refuses invalid target for non-HEAD' ' 180 test_must_fail git symbolic-ref refs/heads/invalid foo..bar 181 ' 182 183 test_expect_success 'symbolic-ref allows top-level target for non-HEAD' ' 184 git symbolic-ref refs/heads/top-level ORIG_HEAD && 185 git update-ref ORIG_HEAD HEAD && 186 test_cmp_rev top-level HEAD 187 ' 188 189 test_expect_success 'symbolic-ref pointing at another' ' 190 git update-ref refs/heads/maint-2.37 HEAD && 191 git symbolic-ref refs/heads/maint refs/heads/maint-2.37 && 192 git checkout maint && 193 194 git symbolic-ref HEAD >actual && 195 echo refs/heads/maint-2.37 >expect && 196 test_cmp expect actual && 197 198 git symbolic-ref --no-recurse HEAD >actual && 199 echo refs/heads/maint >expect && 200 test_cmp expect actual 201 ' 202 203 test_expect_success 'symbolic-ref --short handles complex utf8 case' ' 204 name="测试-加-增加-加-增加" && 205 git symbolic-ref TEST_SYMREF "refs/heads/$name" && 206 # In the real world, we saw problems with this case only 207 # when the locale includes UTF-8. Set it here to try to make things as 208 # hard as possible for us to pass, but in practice we should do the 209 # right thing regardless (and of course some platforms may not even 210 # have this locale). 211 LC_ALL=en_US.UTF-8 git symbolic-ref --short TEST_SYMREF >actual && 212 echo "$name" >expect && 213 test_cmp expect actual 214 ' 215 216 test_expect_success 'symbolic-ref --short handles name with suffix' ' 217 git symbolic-ref TEST_SYMREF "refs/remotes/origin/HEAD" && 218 git symbolic-ref --short TEST_SYMREF >actual && 219 echo "origin" >expect && 220 test_cmp expect actual 221 ' 222 223 test_expect_success 'symbolic-ref --short handles almost-matching name' ' 224 git symbolic-ref TEST_SYMREF "refs/headsXfoo" && 225 git symbolic-ref --short TEST_SYMREF >actual && 226 echo "headsXfoo" >expect && 227 test_cmp expect actual 228 ' 229 230 test_expect_success 'symbolic-ref --short handles name with percent' ' 231 git symbolic-ref TEST_SYMREF "refs/heads/%foo" && 232 git symbolic-ref --short TEST_SYMREF >actual && 233 echo "%foo" >expect && 234 test_cmp expect actual 235 ' 236 237 test_done