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/t1507-rev-parse-upstream.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 / t1507-rev-parse-upstream.sh` 280 lines ยท 7901 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='test @{upstream} syntax' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 11 test_expect_success 'setup' ' 12 13 test_commit 1 && 14 git checkout -b side && 15 test_commit 2 && 16 git checkout main && 17 git clone . clone && 18 test_commit 3 && 19 (cd clone && 20 test_commit 4 && 21 git branch --track my-side origin/side && 22 git branch --track local-main main && 23 git branch --track fun@ny origin/side && 24 git branch --track @funny origin/side && 25 git branch --track funny@ origin/side && 26 git remote add -t main main-only .. && 27 git fetch main-only && 28 git branch bad-upstream && 29 git config branch.bad-upstream.remote main-only && 30 git config branch.bad-upstream.merge refs/heads/side 31 ) 32 ' 33 34 commit_subject () { 35 (cd clone && 36 git show -s --pretty=tformat:%s "$@") 37 } 38 39 error_message () { 40 (cd clone && 41 test_must_fail git rev-parse --verify "$@" 2>../error) 42 } 43 44 test_expect_success '@{upstream} resolves to correct full name' ' 45 echo refs/remotes/origin/main >expect && 46 git -C clone rev-parse --symbolic-full-name @{upstream} >actual && 47 test_cmp expect actual && 48 git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual && 49 test_cmp expect actual && 50 git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual && 51 test_cmp expect actual 52 ' 53 54 test_expect_success '@{u} resolves to correct full name' ' 55 echo refs/remotes/origin/main >expect && 56 git -C clone rev-parse --symbolic-full-name @{u} >actual && 57 test_cmp expect actual && 58 git -C clone rev-parse --symbolic-full-name @{U} >actual && 59 test_cmp expect actual 60 ' 61 62 test_expect_success 'my-side@{upstream} resolves to correct full name' ' 63 echo refs/remotes/origin/side >expect && 64 git -C clone rev-parse --symbolic-full-name my-side@{u} >actual && 65 test_cmp expect actual 66 ' 67 68 test_expect_success 'upstream of branch with @ in middle' ' 69 git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual && 70 echo refs/remotes/origin/side >expect && 71 test_cmp expect actual && 72 git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual && 73 test_cmp expect actual 74 ' 75 76 test_expect_success 'upstream of branch with @ at start' ' 77 git -C clone rev-parse --symbolic-full-name @funny@{u} >actual && 78 echo refs/remotes/origin/side >expect && 79 test_cmp expect actual 80 ' 81 82 test_expect_success 'upstream of branch with @ at end' ' 83 git -C clone rev-parse --symbolic-full-name funny@@{u} >actual && 84 echo refs/remotes/origin/side >expect && 85 test_cmp expect actual 86 ' 87 88 test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' 89 test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream} 90 ' 91 92 test_expect_success 'my-side@{u} resolves to correct commit' ' 93 git checkout side && 94 test_commit 5 && 95 (cd clone && git fetch) && 96 echo 2 >expect && 97 commit_subject my-side >actual && 98 test_cmp expect actual && 99 echo 5 >expect && 100 commit_subject my-side@{u} >actual && 101 test_cmp expect actual 102 ' 103 104 test_expect_success 'not-tracking@{u} fails' ' 105 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} && 106 (cd clone && git checkout --no-track -b non-tracking) && 107 test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} 108 ' 109 110 test_expect_success '@{u}@{1} resolves correctly' ' 111 test_commit 6 && 112 (cd clone && git fetch) && 113 echo 5 >expect && 114 commit_subject my-side@{u}@{1} >actual && 115 test_cmp expect actual && 116 commit_subject my-side@{U}@{1} >actual && 117 test_cmp expect actual 118 ' 119 120 test_expect_success '@{u} without specifying branch fails on a detached HEAD' ' 121 git checkout HEAD^0 && 122 test_must_fail git rev-parse @{u} && 123 test_must_fail git rev-parse @{U} 124 ' 125 126 test_expect_success 'checkout -b new my-side@{u} forks from the same' ' 127 ( 128 cd clone && 129 git checkout -b new my-side@{u} && 130 git rev-parse --symbolic-full-name my-side@{u} >expect && 131 git rev-parse --symbolic-full-name new@{u} >actual && 132 test_cmp expect actual 133 ) 134 ' 135 136 test_expect_success 'merge my-side@{u} records the correct name' ' 137 ( 138 cd clone && 139 git checkout main && 140 test_might_fail git branch -D new && 141 git branch -t new my-side@{u} && 142 git merge -s ours new@{u} && 143 git show -s --pretty=tformat:%s >actual && 144 echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect && 145 test_cmp expect actual 146 ) 147 ' 148 149 test_expect_success 'branch -d other@{u}' ' 150 git checkout -t -b other main && 151 git branch -d @{u} && 152 git for-each-ref refs/heads/main >actual && 153 test_must_be_empty actual 154 ' 155 156 test_expect_success 'checkout other@{u}' ' 157 git branch -f main HEAD && 158 git checkout -t -b another main && 159 git checkout @{u} && 160 git symbolic-ref HEAD >actual && 161 echo refs/heads/main >expect && 162 test_cmp expect actual 163 ' 164 165 test_expect_success 'branch@{u} works when tracking a local branch' ' 166 echo refs/heads/main >expect && 167 git -C clone rev-parse --symbolic-full-name local-main@{u} >actual && 168 test_cmp expect actual 169 ' 170 171 test_expect_success 'branch@{u} error message when no upstream' ' 172 cat >expect <<-EOF && 173 fatal: no upstream configured for branch ${SQ}non-tracking${SQ} 174 EOF 175 error_message non-tracking@{u} && 176 test_cmp expect error 177 ' 178 179 test_expect_success '@{u} error message when no upstream' ' 180 cat >expect <<-EOF && 181 fatal: no upstream configured for branch ${SQ}main${SQ} 182 EOF 183 test_must_fail git rev-parse --verify @{u} 2>actual && 184 test_cmp expect actual 185 ' 186 187 test_expect_success '@{u} silent error when no upstream' ' 188 test_must_fail git rev-parse --verify --quiet @{u} 2>actual && 189 test_must_be_empty actual 190 ' 191 192 test_expect_success 'branch@{u} error message with misspelt branch' ' 193 cat >expect <<-EOF && 194 fatal: no such branch: ${SQ}no-such-branch${SQ} 195 EOF 196 error_message no-such-branch@{u} && 197 test_cmp expect error 198 ' 199 200 test_expect_success '@{u} error message when not on a branch' ' 201 cat >expect <<-EOF && 202 fatal: HEAD does not point to a branch 203 EOF 204 git checkout HEAD^0 && 205 test_must_fail git rev-parse --verify @{u} 2>actual && 206 test_cmp expect actual 207 ' 208 209 test_expect_success 'branch@{u} error message if upstream branch not fetched' ' 210 cat >expect <<-EOF && 211 fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch 212 EOF 213 error_message bad-upstream@{u} && 214 test_cmp expect error 215 ' 216 217 test_expect_success 'pull works when tracking a local branch' ' 218 ( 219 cd clone && 220 git checkout local-main && 221 git pull 222 ) 223 ' 224 225 # makes sense if the previous one succeeded 226 test_expect_success '@{u} works when tracking a local branch' ' 227 echo refs/heads/main >expect && 228 git -C clone rev-parse --symbolic-full-name @{u} >actual && 229 test_cmp expect actual 230 ' 231 232 test_expect_success 'log -g other@{u}' ' 233 commit=$(git rev-parse HEAD) && 234 cat >expect <<-EOF && 235 commit $commit 236 Reflog: main@{0} (C O Mitter ) 237 Reflog message: branch: Created from HEAD 238 Author: A U Thor 239 Date: Thu Apr 7 15:15:13 2005 -0700 240 241 3 242 EOF 243 git log -1 -g other@{u} >actual && 244 test_cmp expect actual 245 ' 246 247 test_expect_success 'log -g other@{u}@{now}' ' 248 commit=$(git rev-parse HEAD) && 249 cat >expect <<-EOF && 250 commit $commit 251 Reflog: main@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter ) 252 Reflog message: branch: Created from HEAD 253 Author: A U Thor 254 Date: Thu Apr 7 15:15:13 2005 -0700 255 256 3 257 EOF 258 git log -1 -g other@{u}@{now} >actual && 259 test_cmp expect actual 260 ' 261 262 test_expect_success '@{reflog}-parsing does not look beyond colon' ' 263 echo content >@{yesterday} && 264 git add @{yesterday} && 265 git commit -m "funny reflog file" && 266 git hash-object @{yesterday} >expect && 267 git rev-parse HEAD:@{yesterday} >actual && 268 test_cmp expect actual 269 ' 270 271 test_expect_success '@{upstream}-parsing does not look beyond colon' ' 272 echo content >@{upstream} && 273 git add @{upstream} && 274 git commit -m "funny upstream file" && 275 git hash-object @{upstream} >expect && 276 git rev-parse HEAD:@{upstream} >actual && 277 test_cmp expect actual 278 ' 279 280 test_done