Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test <branch>@{upstream} syntax' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | |
| 8 | test_expect_success 'setup' ' |
| 9 | |
| 10 | test_commit 1 && |
| 11 | git checkout -b side && |
| 12 | test_commit 2 && |
| 13 | git checkout master && |
| 14 | git clone . clone && |
| 15 | test_commit 3 && |
| 16 | (cd clone && |
| 17 | test_commit 4 && |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 18 | git branch --track my-side origin/side && |
| 19 | git branch --track local-master master && |
Jeff King | 9892d5d | 2014-01-15 03:40:46 -0500 | [diff] [blame] | 20 | git branch --track fun@ny origin/side && |
| 21 | git branch --track @funny origin/side && |
| 22 | git branch --track funny@ origin/side && |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 23 | git remote add -t master master-only .. && |
| 24 | git fetch master-only && |
| 25 | git branch bad-upstream && |
| 26 | git config branch.bad-upstream.remote master-only && |
| 27 | git config branch.bad-upstream.merge refs/heads/side |
| 28 | ) |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 29 | ' |
| 30 | |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 31 | commit_subject () { |
| 32 | (cd clone && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 33 | git show -s --pretty=tformat:%s "$@") |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 34 | } |
| 35 | |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 36 | error_message () { |
| 37 | (cd clone && |
SZEDER Gábor | c3a4456 | 2018-02-24 00:39:43 +0100 | [diff] [blame] | 38 | test_must_fail git rev-parse --verify "$@" 2>../error) |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 41 | test_expect_success '@{upstream} resolves to correct full name' ' |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 42 | echo refs/remotes/origin/master >expect && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 43 | git -C clone rev-parse --symbolic-full-name @{upstream} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 44 | test_cmp expect actual && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 45 | git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 46 | test_cmp expect actual && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 47 | git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 48 | test_cmp expect actual |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 49 | ' |
| 50 | |
| 51 | test_expect_success '@{u} resolves to correct full name' ' |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 52 | echo refs/remotes/origin/master >expect && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 53 | git -C clone rev-parse --symbolic-full-name @{u} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 54 | test_cmp expect actual && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 55 | git -C clone rev-parse --symbolic-full-name @{U} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 56 | test_cmp expect actual |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 57 | ' |
| 58 | |
| 59 | test_expect_success 'my-side@{upstream} resolves to correct full name' ' |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 60 | echo refs/remotes/origin/side >expect && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 61 | git -C clone rev-parse --symbolic-full-name my-side@{u} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 62 | test_cmp expect actual |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 63 | ' |
| 64 | |
Jeff King | 9892d5d | 2014-01-15 03:40:46 -0500 | [diff] [blame] | 65 | test_expect_success 'upstream of branch with @ in middle' ' |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 66 | git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual && |
Jeff King | 9892d5d | 2014-01-15 03:40:46 -0500 | [diff] [blame] | 67 | echo refs/remotes/origin/side >expect && |
Ævar Arnfjörð Bjarmason | 244ea1b | 2017-03-27 11:16:55 +0000 | [diff] [blame] | 68 | test_cmp expect actual && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 69 | git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual && |
Jeff King | 9892d5d | 2014-01-15 03:40:46 -0500 | [diff] [blame] | 70 | test_cmp expect actual |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'upstream of branch with @ at start' ' |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 74 | git -C clone rev-parse --symbolic-full-name @funny@{u} >actual && |
Jeff King | 9892d5d | 2014-01-15 03:40:46 -0500 | [diff] [blame] | 75 | echo refs/remotes/origin/side >expect && |
| 76 | test_cmp expect actual |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'upstream of branch with @ at end' ' |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 80 | git -C clone rev-parse --symbolic-full-name funny@@{u} >actual && |
Jeff King | 9892d5d | 2014-01-15 03:40:46 -0500 | [diff] [blame] | 81 | echo refs/remotes/origin/side >expect && |
| 82 | test_cmp expect actual |
| 83 | ' |
| 84 | |
Kacper Kornet | 617cf93 | 2013-03-17 23:17:09 +0100 | [diff] [blame] | 85 | test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 86 | test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream} |
Kacper Kornet | 617cf93 | 2013-03-17 23:17:09 +0100 | [diff] [blame] | 87 | ' |
| 88 | |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 89 | test_expect_success 'my-side@{u} resolves to correct commit' ' |
| 90 | git checkout side && |
| 91 | test_commit 5 && |
| 92 | (cd clone && git fetch) && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 93 | echo 2 >expect && |
| 94 | commit_subject my-side >actual && |
| 95 | test_cmp expect actual && |
| 96 | echo 5 >expect && |
| 97 | commit_subject my-side@{u} >actual |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 98 | ' |
| 99 | |
| 100 | test_expect_success 'not-tracking@{u} fails' ' |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 101 | test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} && |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 102 | (cd clone && git checkout --no-track -b non-tracking) && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 103 | test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 104 | ' |
| 105 | |
| 106 | test_expect_success '<branch>@{u}@{1} resolves correctly' ' |
| 107 | test_commit 6 && |
| 108 | (cd clone && git fetch) && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 109 | echo 5 >expect && |
| 110 | commit_subject my-side@{u}@{1} >actual && |
| 111 | test_cmp expect actual && |
| 112 | commit_subject my-side@{U}@{1} >actual && |
| 113 | test_cmp expect actual |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 114 | ' |
| 115 | |
| 116 | test_expect_success '@{u} without specifying branch fails on a detached HEAD' ' |
| 117 | git checkout HEAD^0 && |
Ævar Arnfjörð Bjarmason | 244ea1b | 2017-03-27 11:16:55 +0000 | [diff] [blame] | 118 | test_must_fail git rev-parse @{u} && |
| 119 | test_must_fail git rev-parse @{U} |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 120 | ' |
| 121 | |
Junio C Hamano | 69add8e | 2010-01-20 01:08:48 -0800 | [diff] [blame] | 122 | test_expect_success 'checkout -b new my-side@{u} forks from the same' ' |
| 123 | ( |
| 124 | cd clone && |
| 125 | git checkout -b new my-side@{u} && |
| 126 | git rev-parse --symbolic-full-name my-side@{u} >expect && |
| 127 | git rev-parse --symbolic-full-name new@{u} >actual && |
| 128 | test_cmp expect actual |
| 129 | ) |
| 130 | ' |
| 131 | |
Junio C Hamano | ae0ba8e | 2010-01-19 23:17:11 -0800 | [diff] [blame] | 132 | test_expect_success 'merge my-side@{u} records the correct name' ' |
Junio C Hamano | 69add8e | 2010-01-20 01:08:48 -0800 | [diff] [blame] | 133 | ( |
Eric Sunshine | 8327974 | 2018-07-01 20:23:41 -0400 | [diff] [blame] | 134 | cd clone && |
| 135 | git checkout master && |
| 136 | test_might_fail git branch -D new && |
Junio C Hamano | 69add8e | 2010-01-20 01:08:48 -0800 | [diff] [blame] | 137 | git branch -t new my-side@{u} && |
| 138 | git merge -s ours new@{u} && |
Max Kirillov | ad2f725 | 2014-05-15 01:12:45 +0300 | [diff] [blame] | 139 | git show -s --pretty=tformat:%s >actual && |
Junio C Hamano | 2153192 | 2020-07-30 10:06:42 -0700 | [diff] [blame] | 140 | echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect && |
Junio C Hamano | 69add8e | 2010-01-20 01:08:48 -0800 | [diff] [blame] | 141 | test_cmp expect actual |
| 142 | ) |
| 143 | ' |
| 144 | |
Junio C Hamano | ae0ba8e | 2010-01-19 23:17:11 -0800 | [diff] [blame] | 145 | test_expect_success 'branch -d other@{u}' ' |
Junio C Hamano | 69add8e | 2010-01-20 01:08:48 -0800 | [diff] [blame] | 146 | git checkout -t -b other master && |
| 147 | git branch -d @{u} && |
| 148 | git for-each-ref refs/heads/master >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 149 | test_must_be_empty actual |
Junio C Hamano | 69add8e | 2010-01-20 01:08:48 -0800 | [diff] [blame] | 150 | ' |
| 151 | |
Junio C Hamano | ae0ba8e | 2010-01-19 23:17:11 -0800 | [diff] [blame] | 152 | test_expect_success 'checkout other@{u}' ' |
Junio C Hamano | 69add8e | 2010-01-20 01:08:48 -0800 | [diff] [blame] | 153 | git branch -f master HEAD && |
| 154 | git checkout -t -b another master && |
| 155 | git checkout @{u} && |
| 156 | git symbolic-ref HEAD >actual && |
| 157 | echo refs/heads/master >expect && |
| 158 | test_cmp expect actual |
| 159 | ' |
| 160 | |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 161 | test_expect_success 'branch@{u} works when tracking a local branch' ' |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 162 | echo refs/heads/master >expect && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 163 | git -C clone rev-parse --symbolic-full-name local-master@{u} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 164 | test_cmp expect actual |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 165 | ' |
| 166 | |
| 167 | test_expect_success 'branch@{u} error message when no upstream' ' |
| 168 | cat >expect <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 169 | fatal: no upstream configured for branch ${SQ}non-tracking${SQ} |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 170 | EOF |
SZEDER Gábor | c3a4456 | 2018-02-24 00:39:43 +0100 | [diff] [blame] | 171 | error_message non-tracking@{u} && |
| 172 | test_i18ncmp expect error |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 173 | ' |
| 174 | |
| 175 | test_expect_success '@{u} error message when no upstream' ' |
| 176 | cat >expect <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 177 | fatal: no upstream configured for branch ${SQ}master${SQ} |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 178 | EOF |
| 179 | test_must_fail git rev-parse --verify @{u} 2>actual && |
Zbigniew Jędrzejewski-Szmek | 6472028 | 2012-04-14 09:54:35 +0200 | [diff] [blame] | 180 | test_i18ncmp expect actual |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 181 | ' |
| 182 | |
| 183 | test_expect_success 'branch@{u} error message with misspelt branch' ' |
| 184 | cat >expect <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 185 | fatal: no such branch: ${SQ}no-such-branch${SQ} |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 186 | EOF |
SZEDER Gábor | c3a4456 | 2018-02-24 00:39:43 +0100 | [diff] [blame] | 187 | error_message no-such-branch@{u} && |
| 188 | test_i18ncmp expect error |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 189 | ' |
| 190 | |
| 191 | test_expect_success '@{u} error message when not on a branch' ' |
| 192 | cat >expect <<-EOF && |
Ramkumar Ramachandra | 17bf4ff | 2013-05-22 16:09:54 +0530 | [diff] [blame] | 193 | fatal: HEAD does not point to a branch |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 194 | EOF |
| 195 | git checkout HEAD^0 && |
| 196 | test_must_fail git rev-parse --verify @{u} 2>actual && |
Zbigniew Jędrzejewski-Szmek | 6472028 | 2012-04-14 09:54:35 +0200 | [diff] [blame] | 197 | test_i18ncmp expect actual |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 198 | ' |
| 199 | |
| 200 | test_expect_success 'branch@{u} error message if upstream branch not fetched' ' |
| 201 | cat >expect <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 202 | fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 203 | EOF |
SZEDER Gábor | c3a4456 | 2018-02-24 00:39:43 +0100 | [diff] [blame] | 204 | error_message bad-upstream@{u} && |
| 205 | test_i18ncmp expect error |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 206 | ' |
| 207 | |
| 208 | test_expect_success 'pull works when tracking a local branch' ' |
| 209 | ( |
| 210 | cd clone && |
| 211 | git checkout local-master && |
| 212 | git pull |
| 213 | ) |
| 214 | ' |
| 215 | |
| 216 | # makes sense if the previous one succeeded |
| 217 | test_expect_success '@{u} works when tracking a local branch' ' |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 218 | echo refs/heads/master >expect && |
Denton Liu | b441717 | 2019-12-20 10:16:02 -0800 | [diff] [blame] | 219 | git -C clone rev-parse --symbolic-full-name @{u} >actual && |
Denton Liu | 5236fce | 2019-12-20 10:16:00 -0800 | [diff] [blame] | 220 | test_cmp expect actual |
Zbigniew Jędrzejewski-Szmek | 1b4aee9 | 2012-04-14 09:54:31 +0200 | [diff] [blame] | 221 | ' |
| 222 | |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 223 | test_expect_success 'log -g other@{u}' ' |
Denton Liu | 9291e63 | 2019-12-20 10:16:01 -0800 | [diff] [blame] | 224 | commit=$(git rev-parse HEAD) && |
| 225 | cat >expect <<-EOF && |
| 226 | commit $commit |
| 227 | Reflog: master@{0} (C O Mitter <committer@example.com>) |
| 228 | Reflog message: branch: Created from HEAD |
| 229 | Author: A U Thor <author@example.com> |
| 230 | Date: Thu Apr 7 15:15:13 2005 -0700 |
| 231 | |
| 232 | 3 |
| 233 | EOF |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 234 | git log -1 -g other@{u} >actual && |
| 235 | test_cmp expect actual |
| 236 | ' |
| 237 | |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 238 | test_expect_success 'log -g other@{u}@{now}' ' |
Denton Liu | 9291e63 | 2019-12-20 10:16:01 -0800 | [diff] [blame] | 239 | commit=$(git rev-parse HEAD) && |
| 240 | cat >expect <<-EOF && |
| 241 | commit $commit |
| 242 | Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>) |
| 243 | Reflog message: branch: Created from HEAD |
| 244 | Author: A U Thor <author@example.com> |
| 245 | Date: Thu Apr 7 15:15:13 2005 -0700 |
| 246 | |
| 247 | 3 |
| 248 | EOF |
Junio C Hamano | 105e473 | 2010-01-26 13:48:28 -0800 | [diff] [blame] | 249 | git log -1 -g other@{u}@{now} >actual && |
| 250 | test_cmp expect actual |
| 251 | ' |
| 252 | |
Jeff King | 3f6eb30 | 2014-01-15 03:37:23 -0500 | [diff] [blame] | 253 | test_expect_success '@{reflog}-parsing does not look beyond colon' ' |
| 254 | echo content >@{yesterday} && |
| 255 | git add @{yesterday} && |
| 256 | git commit -m "funny reflog file" && |
| 257 | git hash-object @{yesterday} >expect && |
| 258 | git rev-parse HEAD:@{yesterday} >actual |
| 259 | ' |
| 260 | |
| 261 | test_expect_success '@{upstream}-parsing does not look beyond colon' ' |
| 262 | echo content >@{upstream} && |
| 263 | git add @{upstream} && |
| 264 | git commit -m "funny upstream file" && |
| 265 | git hash-object @{upstream} >expect && |
| 266 | git rev-parse HEAD:@{upstream} >actual |
| 267 | ' |
| 268 | |
Johannes Schindelin | 28fb843 | 2009-09-10 17:25:57 +0200 | [diff] [blame] | 269 | test_done |