Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git remote porcelain-ish' |
| 4 | |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 10 | setup_repository () { |
| 11 | mkdir "$1" && ( |
| 12 | cd "$1" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 13 | git init -b main && |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 14 | >file && |
| 15 | git add file && |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 16 | test_tick && |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 17 | git commit -m "Initial" && |
| 18 | git checkout -b side && |
| 19 | >elif && |
| 20 | git add elif && |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 21 | test_tick && |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 22 | git commit -m "Second" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 23 | git checkout main |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 24 | ) |
| 25 | } |
| 26 | |
| 27 | tokens_match () { |
| 28 | echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && |
| 29 | echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && |
Jeff King | 82ebb0b | 2008-03-12 17:36:36 -0400 | [diff] [blame] | 30 | test_cmp expect actual |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | check_remote_track () { |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 34 | actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p') |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 35 | shift && |
| 36 | tokens_match "$*" "$actual" |
| 37 | } |
| 38 | |
| 39 | check_tracking_branch () { |
| 40 | f="" && |
| 41 | r=$(git for-each-ref "--format=%(refname)" | |
| 42 | sed -ne "s|^refs/remotes/$1/||p") && |
| 43 | shift && |
| 44 | tokens_match "$*" "$r" |
| 45 | } |
| 46 | |
| 47 | test_expect_success setup ' |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 48 | setup_repository one && |
| 49 | setup_repository two && |
| 50 | ( |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 51 | cd two && |
| 52 | git branch another |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 53 | ) && |
| 54 | git clone one test |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 55 | ' |
| 56 | |
Johannes Schindelin | d8ff76c | 2016-02-17 17:20:47 +0100 | [diff] [blame] | 57 | test_expect_success 'add remote whose URL agrees with url.<...>.insteadOf' ' |
| 58 | test_config url.git@host.com:team/repo.git.insteadOf myremote && |
| 59 | git remote add myremote git@host.com:team/repo.git |
| 60 | ' |
| 61 | |
Ævar Arnfjörð Bjarmason | a926c4b | 2021-02-11 02:53:51 +0100 | [diff] [blame] | 62 | test_expect_success 'remote information for the origin' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 63 | ( |
| 64 | cd test && |
| 65 | tokens_match origin "$(git remote)" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 66 | check_remote_track origin main side && |
| 67 | check_tracking_branch origin HEAD main side |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 68 | ) |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 69 | ' |
| 70 | |
| 71 | test_expect_success 'add another remote' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 72 | ( |
| 73 | cd test && |
| 74 | git remote add -f second ../two && |
| 75 | tokens_match "origin second" "$(git remote)" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 76 | check_tracking_branch second main side another && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 77 | git for-each-ref "--format=%(refname)" refs/remotes | |
| 78 | sed -e "/^refs\/remotes\/origin\//d" \ |
| 79 | -e "/^refs\/remotes\/second\//d" >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 80 | test_must_be_empty actual |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 81 | ) |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 82 | ' |
| 83 | |
Ævar Arnfjörð Bjarmason | a926c4b | 2021-02-11 02:53:51 +0100 | [diff] [blame] | 84 | test_expect_success 'check remote-tracking' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 85 | ( |
| 86 | cd test && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 87 | check_remote_track origin main side && |
| 88 | check_remote_track second main side another |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 89 | ) |
Jiang Xin | f7dc6a9 | 2012-08-27 13:36:54 +0800 | [diff] [blame] | 90 | ' |
| 91 | |
Jeff King | 1ce89cc | 2008-04-22 07:11:13 -0400 | [diff] [blame] | 92 | test_expect_success 'remote forces tracking branches' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 93 | ( |
| 94 | cd test && |
Elia Pinto | c009781 | 2015-12-23 14:45:53 +0100 | [diff] [blame] | 95 | case $(git config remote.second.fetch) in |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 96 | +*) true ;; |
| 97 | *) false ;; |
| 98 | esac |
| 99 | ) |
Jeff King | 1ce89cc | 2008-04-22 07:11:13 -0400 | [diff] [blame] | 100 | ' |
| 101 | |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 102 | test_expect_success 'remove remote' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 103 | ( |
| 104 | cd test && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 105 | git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/main && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 106 | git remote rm second |
| 107 | ) |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 108 | ' |
| 109 | |
Ævar Arnfjörð Bjarmason | a926c4b | 2021-02-11 02:53:51 +0100 | [diff] [blame] | 110 | test_expect_success 'remove remote' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 111 | ( |
| 112 | cd test && |
| 113 | tokens_match origin "$(git remote)" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 114 | check_remote_track origin main side && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 115 | git for-each-ref "--format=%(refname)" refs/remotes | |
| 116 | sed -e "/^refs\/remotes\/origin\//d" >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 117 | test_must_be_empty actual |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 118 | ) |
Junio C Hamano | 683b567 | 2007-09-23 22:29:12 -0700 | [diff] [blame] | 119 | ' |
| 120 | |
Matthieu Moy | 1393123 | 2010-11-02 16:31:25 +0100 | [diff] [blame] | 121 | test_expect_success 'remove remote protects local branches' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 122 | ( |
| 123 | cd test && |
| 124 | cat >expect1 <<-\EOF && |
| 125 | Note: A branch outside the refs/remotes/ hierarchy was not removed; |
| 126 | to delete it, use: |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 127 | git branch -d main |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 128 | EOF |
| 129 | cat >expect2 <<-\EOF && |
| 130 | Note: Some branches outside the refs/remotes/ hierarchy were not removed; |
| 131 | to delete them, use: |
| 132 | git branch -d foobranch |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 133 | git branch -d main |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 134 | EOF |
| 135 | git tag footag && |
| 136 | git config --add remote.oops.fetch "+refs/*:refs/*" && |
| 137 | git remote remove oops 2>actual1 && |
| 138 | git branch foobranch && |
| 139 | git config --add remote.oops.fetch "+refs/*:refs/*" && |
| 140 | git remote rm oops 2>actual2 && |
| 141 | git branch -d foobranch && |
| 142 | git tag -d footag && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 143 | test_cmp expect1 actual1 && |
| 144 | test_cmp expect2 actual2 |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 145 | ) |
Jay Soffian | 441adf0 | 2009-02-04 11:06:07 -0500 | [diff] [blame] | 146 | ' |
| 147 | |
Thomas Gummerer | cc8e538 | 2016-02-16 10:47:51 +0100 | [diff] [blame] | 148 | test_expect_success 'remove errors out early when deleting non-existent branch' ' |
| 149 | ( |
| 150 | cd test && |
Ævar Arnfjörð Bjarmason | 9144ba4 | 2020-10-27 10:41:36 +0100 | [diff] [blame] | 151 | echo "error: No such remote: '\''foo'\''" >expect && |
| 152 | test_expect_code 2 git remote rm foo 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 153 | test_cmp expect actual |
Thomas Gummerer | cc8e538 | 2016-02-16 10:47:51 +0100 | [diff] [blame] | 154 | ) |
| 155 | ' |
| 156 | |
Ross Lagerwall | 20690b2 | 2017-02-18 00:23:41 +0000 | [diff] [blame] | 157 | test_expect_success 'remove remote with a branch without configured merge' ' |
| 158 | test_when_finished "( |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 159 | git -C test checkout main; |
Ross Lagerwall | 20690b2 | 2017-02-18 00:23:41 +0000 | [diff] [blame] | 160 | git -C test branch -D two; |
| 161 | git -C test config --remove-section remote.two; |
| 162 | git -C test config --remove-section branch.second; |
| 163 | true |
| 164 | )" && |
| 165 | ( |
| 166 | cd test && |
| 167 | git remote add two ../two && |
| 168 | git fetch two && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 169 | git checkout -b second two/main^0 && |
Ross Lagerwall | 20690b2 | 2017-02-18 00:23:41 +0000 | [diff] [blame] | 170 | git config branch.second.remote two && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 171 | git checkout main && |
Ross Lagerwall | 20690b2 | 2017-02-18 00:23:41 +0000 | [diff] [blame] | 172 | git remote rm two |
| 173 | ) |
| 174 | ' |
| 175 | |
Thomas Gummerer | cc8e538 | 2016-02-16 10:47:51 +0100 | [diff] [blame] | 176 | test_expect_success 'rename errors out early when deleting non-existent branch' ' |
| 177 | ( |
| 178 | cd test && |
Ævar Arnfjörð Bjarmason | 9144ba4 | 2020-10-27 10:41:36 +0100 | [diff] [blame] | 179 | echo "error: No such remote: '\''foo'\''" >expect && |
| 180 | test_expect_code 2 git remote rename foo bar 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 181 | test_cmp expect actual |
Thomas Gummerer | cc8e538 | 2016-02-16 10:47:51 +0100 | [diff] [blame] | 182 | ) |
| 183 | ' |
| 184 | |
Andrei Rybak | abcb66c | 2021-06-11 13:18:50 +0200 | [diff] [blame] | 185 | test_expect_success 'rename errors out early when new name is invalid' ' |
Sean Barag | 444825c | 2020-10-01 03:46:12 +0000 | [diff] [blame] | 186 | test_config remote.foo.vcs bar && |
| 187 | echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect && |
| 188 | test_must_fail git remote rename foo invalid...name 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 189 | test_cmp expect actual |
Sean Barag | 444825c | 2020-10-01 03:46:12 +0000 | [diff] [blame] | 190 | ' |
| 191 | |
Thomas Gummerer | a31eeae | 2016-02-16 10:47:52 +0100 | [diff] [blame] | 192 | test_expect_success 'add existing foreign_vcs remote' ' |
| 193 | test_config remote.foo.vcs bar && |
Ævar Arnfjörð Bjarmason | 9144ba4 | 2020-10-27 10:41:36 +0100 | [diff] [blame] | 194 | echo "error: remote foo already exists." >expect && |
| 195 | test_expect_code 3 git remote add foo bar 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 196 | test_cmp expect actual |
Thomas Gummerer | a31eeae | 2016-02-16 10:47:52 +0100 | [diff] [blame] | 197 | ' |
| 198 | |
| 199 | test_expect_success 'add existing foreign_vcs remote' ' |
| 200 | test_config remote.foo.vcs bar && |
| 201 | test_config remote.bar.vcs bar && |
Ævar Arnfjörð Bjarmason | 9144ba4 | 2020-10-27 10:41:36 +0100 | [diff] [blame] | 202 | echo "error: remote bar already exists." >expect && |
| 203 | test_expect_code 3 git remote rename foo bar 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 204 | test_cmp expect actual |
Thomas Gummerer | a31eeae | 2016-02-16 10:47:52 +0100 | [diff] [blame] | 205 | ' |
| 206 | |
Sean Barag | 444825c | 2020-10-01 03:46:12 +0000 | [diff] [blame] | 207 | test_expect_success 'add invalid foreign_vcs remote' ' |
| 208 | echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect && |
| 209 | test_must_fail git remote add invalid...name bar 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 210 | test_cmp expect actual |
Sean Barag | 444825c | 2020-10-01 03:46:12 +0000 | [diff] [blame] | 211 | ' |
| 212 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 213 | cat >test/expect <<EOF |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 214 | * remote origin |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 215 | Fetch URL: $(pwd)/one |
| 216 | Push URL: $(pwd)/one |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 217 | HEAD branch: main |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 218 | Remote branches: |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 219 | main new (next fetch will store in remotes/origin) |
| 220 | side tracked |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 221 | Local branches configured for 'git pull': |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 222 | ahead merges with remote main |
| 223 | main merges with remote main |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 224 | octopus merges with remote topic-a |
| 225 | and with remote topic-b |
| 226 | and with remote topic-c |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 227 | rebase rebases onto remote main |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 228 | Local refs configured for 'git push': |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 229 | main pushes to main (local out of date) |
| 230 | main pushes to upstream (create) |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 231 | * remote two |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 232 | Fetch URL: ../two |
| 233 | Push URL: ../three |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 234 | HEAD branch: main |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 235 | Local refs configured for 'git push': |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 236 | ahead forces to main (fast-forwardable) |
| 237 | main pushes to another (up to date) |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 238 | EOF |
| 239 | |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 240 | test_expect_success 'show' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 241 | ( |
| 242 | cd test && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 243 | git config --add remote.origin.fetch refs/heads/main:refs/heads/upstream && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 244 | git fetch && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 245 | git checkout -b ahead origin/main && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 246 | echo 1 >>file && |
| 247 | test_tick && |
| 248 | git commit -m update file && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 249 | git checkout main && |
| 250 | git branch --track octopus origin/main && |
| 251 | git branch --track rebase origin/main && |
| 252 | git branch -d -r origin/main && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 253 | git config --add remote.two.url ../two && |
| 254 | git config --add remote.two.pushurl ../three && |
| 255 | git config branch.rebase.rebase true && |
| 256 | git config branch.octopus.merge "topic-a topic-b topic-c" && |
| 257 | ( |
| 258 | cd ../one && |
| 259 | echo 1 >file && |
| 260 | test_tick && |
| 261 | git commit -m update file |
| 262 | ) && |
| 263 | git config --add remote.origin.push : && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 264 | git config --add remote.origin.push refs/heads/main:refs/heads/upstream && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 265 | git config --add remote.origin.push +refs/tags/lastbackup && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 266 | git config --add remote.two.push +refs/heads/ahead:refs/heads/main && |
| 267 | git config --add remote.two.push refs/heads/main:refs/heads/another && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 268 | git remote show origin two >output && |
| 269 | git branch -d rebase octopus && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 270 | test_cmp expect output |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 271 | ) |
Johannes Schindelin | 4704640 | 2008-02-29 01:45:24 +0000 | [diff] [blame] | 272 | ' |
| 273 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 274 | cat >test/expect <<EOF |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 275 | * remote origin |
Michael J Gruber | 857f8c3 | 2009-06-13 18:29:10 +0200 | [diff] [blame] | 276 | Fetch URL: $(pwd)/one |
| 277 | Push URL: $(pwd)/one |
Jay Soffian | e61e0cc | 2009-02-25 03:32:24 -0500 | [diff] [blame] | 278 | HEAD branch: (not queried) |
Jay Soffian | 7ecbbf8 | 2009-02-25 03:32:27 -0500 | [diff] [blame] | 279 | Remote branches: (status not queried) |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 280 | main |
Johannes Sixt | 20244ea | 2008-10-22 09:39:47 +0200 | [diff] [blame] | 281 | side |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 282 | Local branches configured for 'git pull': |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 283 | ahead merges with remote main |
| 284 | main merges with remote main |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 285 | Local refs configured for 'git push' (status not queried): |
| 286 | (matching) pushes to (matching) |
Johannes Schindelin | 66713e8 | 2020-10-23 14:00:05 +0000 | [diff] [blame] | 287 | refs/heads/main pushes to refs/heads/upstream |
Jay Soffian | e5dcbfd | 2009-02-25 03:32:28 -0500 | [diff] [blame] | 288 | refs/tags/lastbackup forces to refs/tags/lastbackup |
Olivier Marin | 0ecfcb3 | 2008-06-10 16:51:08 +0200 | [diff] [blame] | 289 | EOF |
| 290 | |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 291 | test_expect_success 'show -n' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 292 | mv one one.unreachable && |
| 293 | ( |
| 294 | cd test && |
| 295 | git remote show -n origin >output && |
| 296 | mv ../one.unreachable ../one && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 297 | test_cmp expect output |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 298 | ) |
| 299 | ' |
| 300 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 301 | test_expect_success 'prune' ' |
| 302 | ( |
| 303 | cd one && |
| 304 | git branch -m side side2 |
| 305 | ) && |
| 306 | ( |
| 307 | cd test && |
| 308 | git fetch origin && |
| 309 | git remote prune origin && |
| 310 | git rev-parse refs/remotes/origin/side2 && |
| 311 | test_must_fail git rev-parse refs/remotes/origin/side |
| 312 | ) |
| 313 | ' |
| 314 | |
| 315 | test_expect_success 'set-head --delete' ' |
| 316 | ( |
| 317 | cd test && |
| 318 | git symbolic-ref refs/remotes/origin/HEAD && |
| 319 | git remote set-head --delete origin && |
| 320 | test_must_fail git symbolic-ref refs/remotes/origin/HEAD |
| 321 | ) |
| 322 | ' |
| 323 | |
| 324 | test_expect_success 'set-head --auto' ' |
| 325 | ( |
| 326 | cd test && |
| 327 | git remote set-head --auto origin && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 328 | echo refs/remotes/origin/main >expect && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 329 | git symbolic-ref refs/remotes/origin/HEAD >output && |
| 330 | test_cmp expect output |
| 331 | ) |
| 332 | ' |
| 333 | |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 334 | test_expect_success 'set-head --auto has no problem w/multiple HEADs' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 335 | ( |
| 336 | cd test && |
Junio C Hamano | a4dfee0 | 2013-09-17 21:45:34 -0700 | [diff] [blame] | 337 | git fetch two "refs/heads/*:refs/remotes/two/*" && |
Junio C Hamano | a45b5f0 | 2013-09-17 19:10:31 -0700 | [diff] [blame] | 338 | git remote set-head --auto two >output 2>&1 && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 339 | echo "two/HEAD set to main" >expect && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 340 | test_cmp expect output |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 341 | ) |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 342 | ' |
| 343 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 344 | cat >test/expect <<\EOF |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 345 | refs/remotes/origin/side2 |
| 346 | EOF |
| 347 | |
| 348 | test_expect_success 'set-head explicit' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 349 | ( |
| 350 | cd test && |
| 351 | git remote set-head origin side2 && |
| 352 | git symbolic-ref refs/remotes/origin/HEAD >output && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 353 | git remote set-head origin main && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 354 | test_cmp expect output |
| 355 | ) |
Jay Soffian | bc14fac | 2009-02-25 03:32:25 -0500 | [diff] [blame] | 356 | ' |
| 357 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 358 | cat >test/expect <<EOF |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 359 | Pruning origin |
Johan Herland | 86521ac | 2008-09-01 21:07:33 +0200 | [diff] [blame] | 360 | URL: $(pwd)/one |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 361 | * [would prune] origin/side2 |
| 362 | EOF |
| 363 | |
| 364 | test_expect_success 'prune --dry-run' ' |
Eric Sunshine | 431f4a2 | 2018-07-01 20:23:48 -0400 | [diff] [blame] | 365 | git -C one branch -m side2 side && |
| 366 | test_when_finished "git -C one branch -m side side2" && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 367 | ( |
| 368 | cd test && |
| 369 | git remote prune --dry-run origin >output && |
| 370 | git rev-parse refs/remotes/origin/side2 && |
| 371 | test_must_fail git rev-parse refs/remotes/origin/side && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 372 | test_cmp expect output |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 373 | ) |
Olivier Marin | 8d76792 | 2008-06-10 16:51:35 +0200 | [diff] [blame] | 374 | ' |
| 375 | |
Johannes Schindelin | 4ebc914 | 2008-02-29 01:46:07 +0000 | [diff] [blame] | 376 | test_expect_success 'add --mirror && prune' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 377 | mkdir mirror && |
| 378 | ( |
| 379 | cd mirror && |
| 380 | git init --bare && |
| 381 | git remote add --mirror -f origin ../one |
| 382 | ) && |
| 383 | ( |
| 384 | cd one && |
| 385 | git branch -m side2 side |
| 386 | ) && |
| 387 | ( |
| 388 | cd mirror && |
| 389 | git rev-parse --verify refs/heads/side2 && |
| 390 | test_must_fail git rev-parse --verify refs/heads/side && |
| 391 | git fetch origin && |
| 392 | git remote prune origin && |
| 393 | test_must_fail git rev-parse --verify refs/heads/side2 && |
| 394 | git rev-parse --verify refs/heads/side |
| 395 | ) |
Johannes Schindelin | 4ebc914 | 2008-02-29 01:46:07 +0000 | [diff] [blame] | 396 | ' |
| 397 | |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 398 | test_expect_success 'add --mirror=fetch' ' |
| 399 | mkdir mirror-fetch && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 400 | git init -b main mirror-fetch/parent && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 401 | ( |
| 402 | cd mirror-fetch/parent && |
| 403 | test_commit one |
| 404 | ) && |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 405 | git init --bare mirror-fetch/child && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 406 | ( |
| 407 | cd mirror-fetch/child && |
| 408 | git remote add --mirror=fetch -f parent ../parent |
| 409 | ) |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 410 | ' |
| 411 | |
| 412 | test_expect_success 'fetch mirrors act as mirrors during fetch' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 413 | ( |
| 414 | cd mirror-fetch/parent && |
| 415 | git branch new && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 416 | git branch -m main renamed |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 417 | ) && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 418 | ( |
| 419 | cd mirror-fetch/child && |
| 420 | git fetch parent && |
| 421 | git rev-parse --verify refs/heads/new && |
| 422 | git rev-parse --verify refs/heads/renamed |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 423 | ) |
| 424 | ' |
| 425 | |
| 426 | test_expect_success 'fetch mirrors can prune' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 427 | ( |
| 428 | cd mirror-fetch/child && |
| 429 | git remote prune parent && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 430 | test_must_fail git rev-parse --verify refs/heads/main |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 431 | ) |
| 432 | ' |
| 433 | |
| 434 | test_expect_success 'fetch mirrors do not act as mirrors during push' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 435 | ( |
| 436 | cd mirror-fetch/parent && |
| 437 | git checkout HEAD^0 |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 438 | ) && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 439 | ( |
| 440 | cd mirror-fetch/child && |
| 441 | git branch -m renamed renamed2 && |
| 442 | git push parent : |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 443 | ) && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 444 | ( |
| 445 | cd mirror-fetch/parent && |
| 446 | git rev-parse --verify renamed && |
| 447 | test_must_fail git rev-parse --verify refs/heads/renamed2 |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 448 | ) |
| 449 | ' |
| 450 | |
Jeff King | 3eafdc9 | 2011-05-26 11:11:00 -0400 | [diff] [blame] | 451 | test_expect_success 'add fetch mirror with specific branches' ' |
| 452 | git init --bare mirror-fetch/track && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 453 | ( |
| 454 | cd mirror-fetch/track && |
| 455 | git remote add --mirror=fetch -t heads/new parent ../parent |
Jeff King | 3eafdc9 | 2011-05-26 11:11:00 -0400 | [diff] [blame] | 456 | ) |
| 457 | ' |
| 458 | |
| 459 | test_expect_success 'fetch mirror respects specific branches' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 460 | ( |
| 461 | cd mirror-fetch/track && |
| 462 | git fetch parent && |
| 463 | git rev-parse --verify refs/heads/new && |
| 464 | test_must_fail git rev-parse --verify refs/heads/renamed |
Jeff King | 3eafdc9 | 2011-05-26 11:11:00 -0400 | [diff] [blame] | 465 | ) |
| 466 | ' |
| 467 | |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 468 | test_expect_success 'add --mirror=push' ' |
| 469 | mkdir mirror-push && |
| 470 | git init --bare mirror-push/public && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 471 | git init -b main mirror-push/private && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 472 | ( |
| 473 | cd mirror-push/private && |
| 474 | test_commit one && |
| 475 | git remote add --mirror=push public ../public |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 476 | ) |
| 477 | ' |
| 478 | |
| 479 | test_expect_success 'push mirrors act as mirrors during push' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 480 | ( |
| 481 | cd mirror-push/private && |
| 482 | git branch new && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 483 | git branch -m main renamed && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 484 | git push public |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 485 | ) && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 486 | ( |
| 487 | cd mirror-push/private && |
| 488 | git rev-parse --verify refs/heads/new && |
| 489 | git rev-parse --verify refs/heads/renamed && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 490 | test_must_fail git rev-parse --verify refs/heads/main |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 491 | ) |
| 492 | ' |
| 493 | |
| 494 | test_expect_success 'push mirrors do not act as mirrors during fetch' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 495 | ( |
| 496 | cd mirror-push/public && |
| 497 | git branch -m renamed renamed2 && |
| 498 | git symbolic-ref HEAD refs/heads/renamed2 |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 499 | ) && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 500 | ( |
| 501 | cd mirror-push/private && |
| 502 | git fetch public && |
| 503 | git rev-parse --verify refs/heads/renamed && |
| 504 | test_must_fail git rev-parse --verify refs/heads/renamed2 |
Jeff King | a9f5a35 | 2011-03-30 15:53:19 -0400 | [diff] [blame] | 505 | ) |
| 506 | ' |
| 507 | |
Jeff King | 3eafdc9 | 2011-05-26 11:11:00 -0400 | [diff] [blame] | 508 | test_expect_success 'push mirrors do not allow you to specify refs' ' |
| 509 | git init mirror-push/track && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 510 | ( |
| 511 | cd mirror-push/track && |
| 512 | test_must_fail git remote add --mirror=push -t new public ../public |
Jeff King | 3eafdc9 | 2011-05-26 11:11:00 -0400 | [diff] [blame] | 513 | ) |
| 514 | ' |
| 515 | |
Shawn O. Pearce | c175a7a | 2008-05-31 23:58:05 -0400 | [diff] [blame] | 516 | test_expect_success 'add alt && prune' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 517 | mkdir alttst && |
| 518 | ( |
| 519 | cd alttst && |
| 520 | git init && |
| 521 | git remote add -f origin ../one && |
| 522 | git config remote.alt.url ../one && |
| 523 | git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*" |
| 524 | ) && |
| 525 | ( |
| 526 | cd one && |
| 527 | git branch -m side side2 |
| 528 | ) && |
| 529 | ( |
| 530 | cd alttst && |
| 531 | git rev-parse --verify refs/remotes/origin/side && |
| 532 | test_must_fail git rev-parse --verify refs/remotes/origin/side2 && |
| 533 | git fetch alt && |
| 534 | git remote prune alt && |
| 535 | test_must_fail git rev-parse --verify refs/remotes/origin/side && |
| 536 | git rev-parse --verify refs/remotes/origin/side2 |
| 537 | ) |
Shawn O. Pearce | c175a7a | 2008-05-31 23:58:05 -0400 | [diff] [blame] | 538 | ' |
| 539 | |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 540 | cat >test/expect <<\EOF |
| 541 | some-tag |
| 542 | EOF |
| 543 | |
| 544 | test_expect_success 'add with reachable tags (default)' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 545 | ( |
| 546 | cd one && |
| 547 | >foobar && |
| 548 | git add foobar && |
| 549 | git commit -m "Foobar" && |
| 550 | git tag -a -m "Foobar tag" foobar-tag && |
| 551 | git reset --hard HEAD~1 && |
| 552 | git tag -a -m "Some tag" some-tag |
| 553 | ) && |
| 554 | mkdir add-tags && |
| 555 | ( |
| 556 | cd add-tags && |
| 557 | git init && |
| 558 | git remote add -f origin ../one && |
| 559 | git tag -l some-tag >../test/output && |
| 560 | git tag -l foobar-tag >>../test/output && |
| 561 | test_must_fail git config remote.origin.tagopt |
| 562 | ) && |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 563 | test_cmp test/expect test/output |
| 564 | ' |
| 565 | |
| 566 | cat >test/expect <<\EOF |
| 567 | some-tag |
| 568 | foobar-tag |
| 569 | --tags |
| 570 | EOF |
| 571 | |
| 572 | test_expect_success 'add --tags' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 573 | rm -rf add-tags && |
| 574 | ( |
| 575 | mkdir add-tags && |
| 576 | cd add-tags && |
| 577 | git init && |
| 578 | git remote add -f --tags origin ../one && |
| 579 | git tag -l some-tag >../test/output && |
| 580 | git tag -l foobar-tag >>../test/output && |
| 581 | git config remote.origin.tagopt >>../test/output |
| 582 | ) && |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 583 | test_cmp test/expect test/output |
| 584 | ' |
| 585 | |
| 586 | cat >test/expect <<\EOF |
| 587 | --no-tags |
| 588 | EOF |
| 589 | |
| 590 | test_expect_success 'add --no-tags' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 591 | rm -rf add-tags && |
| 592 | ( |
| 593 | mkdir add-no-tags && |
| 594 | cd add-no-tags && |
| 595 | git init && |
| 596 | git remote add -f --no-tags origin ../one && |
Ævar Arnfjörð Bjarmason | bfa9148 | 2021-02-25 02:21:16 +0100 | [diff] [blame] | 597 | grep tagOpt .git/config && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 598 | git tag -l some-tag >../test/output && |
| 599 | git tag -l foobar-tag >../test/output && |
| 600 | git config remote.origin.tagopt >>../test/output |
| 601 | ) && |
| 602 | ( |
| 603 | cd one && |
| 604 | git tag -d some-tag foobar-tag |
| 605 | ) && |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 606 | test_cmp test/expect test/output |
| 607 | ' |
| 608 | |
| 609 | test_expect_success 'reject --no-no-tags' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 610 | ( |
| 611 | cd add-no-tags && |
| 612 | test_must_fail git remote add -f --no-no-tags neworigin ../one |
| 613 | ) |
Samuel Tardieu | 111fb85 | 2010-04-20 01:31:31 +0200 | [diff] [blame] | 614 | ' |
| 615 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 616 | cat >one/expect <<\EOF |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 617 | apis/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 618 | apis/side |
| 619 | drosophila/another |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 620 | drosophila/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 621 | drosophila/side |
| 622 | EOF |
| 623 | |
| 624 | test_expect_success 'update' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 625 | ( |
| 626 | cd one && |
| 627 | git remote add drosophila ../two && |
| 628 | git remote add apis ../mirror && |
| 629 | git remote update && |
| 630 | git branch -r >output && |
| 631 | test_cmp expect output |
| 632 | ) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 633 | ' |
| 634 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 635 | cat >one/expect <<\EOF |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 636 | drosophila/another |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 637 | drosophila/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 638 | drosophila/side |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 639 | manduca/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 640 | manduca/side |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 641 | megaloprepus/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 642 | megaloprepus/side |
| 643 | EOF |
| 644 | |
| 645 | test_expect_success 'update with arguments' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 646 | ( |
| 647 | cd one && |
| 648 | for b in $(git branch -r) |
| 649 | do |
Jeff King | e6821d0 | 2015-03-25 01:29:52 -0400 | [diff] [blame] | 650 | git branch -r -d $b || exit 1 |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 651 | done && |
| 652 | git remote add manduca ../mirror && |
| 653 | git remote add megaloprepus ../mirror && |
| 654 | git config remotes.phobaeticus "drosophila megaloprepus" && |
| 655 | git config remotes.titanus manduca && |
| 656 | git remote update phobaeticus titanus && |
| 657 | git branch -r >output && |
| 658 | test_cmp expect output |
| 659 | ) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 660 | ' |
| 661 | |
Björn Gustavsson | e2d41c6 | 2009-11-09 21:11:59 +0100 | [diff] [blame] | 662 | test_expect_success 'update --prune' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 663 | ( |
| 664 | cd one && |
| 665 | git branch -m side2 side3 |
| 666 | ) && |
| 667 | ( |
| 668 | cd test && |
| 669 | git remote update --prune && |
| 670 | ( |
| 671 | cd ../one && |
| 672 | git branch -m side3 side2 |
| 673 | ) && |
| 674 | git rev-parse refs/remotes/origin/side3 && |
| 675 | test_must_fail git rev-parse refs/remotes/origin/side2 |
| 676 | ) |
Björn Gustavsson | e2d41c6 | 2009-11-09 21:11:59 +0100 | [diff] [blame] | 677 | ' |
| 678 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 679 | cat >one/expect <<-\EOF |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 680 | apis/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 681 | apis/side |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 682 | manduca/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 683 | manduca/side |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 684 | megaloprepus/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 685 | megaloprepus/side |
| 686 | EOF |
| 687 | |
| 688 | test_expect_success 'update default' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 689 | ( |
| 690 | cd one && |
| 691 | for b in $(git branch -r) |
| 692 | do |
Jeff King | e6821d0 | 2015-03-25 01:29:52 -0400 | [diff] [blame] | 693 | git branch -r -d $b || exit 1 |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 694 | done && |
| 695 | git config remote.drosophila.skipDefaultUpdate true && |
| 696 | git remote update default && |
| 697 | git branch -r >output && |
| 698 | test_cmp expect output |
| 699 | ) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 700 | ' |
| 701 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 702 | cat >one/expect <<\EOF |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 703 | drosophila/another |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 704 | drosophila/main |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 705 | drosophila/side |
| 706 | EOF |
| 707 | |
| 708 | test_expect_success 'update default (overridden, with funny whitespace)' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 709 | ( |
| 710 | cd one && |
| 711 | for b in $(git branch -r) |
| 712 | do |
Jeff King | e6821d0 | 2015-03-25 01:29:52 -0400 | [diff] [blame] | 713 | git branch -r -d $b || exit 1 |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 714 | done && |
| 715 | git config remotes.default "$(printf "\t drosophila \n")" && |
| 716 | git remote update default && |
| 717 | git branch -r >output && |
| 718 | test_cmp expect output |
| 719 | ) |
Johannes Schindelin | 84521ed | 2008-03-04 11:23:53 +0000 | [diff] [blame] | 720 | ' |
| 721 | |
Björn Gustavsson | 4f2e842 | 2009-12-31 10:43:17 +0100 | [diff] [blame] | 722 | test_expect_success 'update (with remotes.default defined)' ' |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 723 | ( |
| 724 | cd one && |
| 725 | for b in $(git branch -r) |
| 726 | do |
Jeff King | e6821d0 | 2015-03-25 01:29:52 -0400 | [diff] [blame] | 727 | git branch -r -d $b || exit 1 |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 728 | done && |
| 729 | git config remotes.default "drosophila" && |
| 730 | git remote update && |
| 731 | git branch -r >output && |
| 732 | test_cmp expect output |
| 733 | ) |
Björn Gustavsson | 4f2e842 | 2009-12-31 10:43:17 +0100 | [diff] [blame] | 734 | ' |
| 735 | |
Johannes Schindelin | 740fdd2 | 2008-03-19 00:27:42 +0000 | [diff] [blame] | 736 | test_expect_success '"remote show" does not show symbolic refs' ' |
Johannes Schindelin | 740fdd2 | 2008-03-19 00:27:42 +0000 | [diff] [blame] | 737 | git clone one three && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 738 | ( |
| 739 | cd three && |
| 740 | git remote show origin >output && |
| 741 | ! grep "^ *HEAD$" < output && |
| 742 | ! grep -i stale < output |
| 743 | ) |
Johannes Schindelin | 740fdd2 | 2008-03-19 00:27:42 +0000 | [diff] [blame] | 744 | ' |
| 745 | |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 746 | test_expect_success 'reject adding remote with an invalid name' ' |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 747 | test_must_fail git remote add some:url desired-name |
Jonas Fonseca | 24b6177 | 2008-04-13 11:56:54 +0200 | [diff] [blame] | 748 | ' |
| 749 | |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 750 | # The first three test if the tracking branches are properly renamed, |
| 751 | # the last two ones check if the config is updated. |
| 752 | |
| 753 | test_expect_success 'rename a remote' ' |
Bert Wesarg | b3fd6cb | 2020-02-01 10:34:09 +0100 | [diff] [blame] | 754 | test_config_global remote.pushDefault origin && |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 755 | git clone one four && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 756 | ( |
| 757 | cd four && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 758 | git config branch.main.pushRemote origin && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 759 | git remote rename origin upstream && |
Ævar Arnfjörð Bjarmason | 0f1da60 | 2021-02-25 02:21:17 +0100 | [diff] [blame] | 760 | grep "pushRemote" .git/config && |
Michael Haggerty | 2eb7a0e | 2017-01-06 17:22:23 +0100 | [diff] [blame] | 761 | test -z "$(git for-each-ref refs/remotes/origin)" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 762 | test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" && |
| 763 | test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 764 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 765 | test "$(git config branch.main.remote)" = "upstream" && |
| 766 | test "$(git config branch.main.pushRemote)" = "upstream" && |
Bert Wesarg | b3fd6cb | 2020-02-01 10:34:09 +0100 | [diff] [blame] | 767 | test "$(git config --global remote.pushDefault)" = "origin" |
| 768 | ) |
| 769 | ' |
| 770 | |
| 771 | test_expect_success 'rename a remote renames repo remote.pushDefault' ' |
| 772 | git clone one four.1 && |
| 773 | ( |
| 774 | cd four.1 && |
| 775 | git config remote.pushDefault origin && |
| 776 | git remote rename origin upstream && |
Ævar Arnfjörð Bjarmason | 0f1da60 | 2021-02-25 02:21:17 +0100 | [diff] [blame] | 777 | grep pushDefault .git/config && |
Bert Wesarg | b3fd6cb | 2020-02-01 10:34:09 +0100 | [diff] [blame] | 778 | test "$(git config --local remote.pushDefault)" = "upstream" |
| 779 | ) |
| 780 | ' |
| 781 | |
| 782 | test_expect_success 'rename a remote renames repo remote.pushDefault but ignores global' ' |
| 783 | test_config_global remote.pushDefault other && |
| 784 | git clone one four.2 && |
| 785 | ( |
| 786 | cd four.2 && |
| 787 | git config remote.pushDefault origin && |
| 788 | git remote rename origin upstream && |
| 789 | test "$(git config --global remote.pushDefault)" = "other" && |
| 790 | test "$(git config --local remote.pushDefault)" = "upstream" |
| 791 | ) |
| 792 | ' |
| 793 | |
| 794 | test_expect_success 'rename a remote renames repo remote.pushDefault but keeps global' ' |
| 795 | test_config_global remote.pushDefault origin && |
| 796 | git clone one four.3 && |
| 797 | ( |
| 798 | cd four.3 && |
| 799 | git config remote.pushDefault origin && |
| 800 | git remote rename origin upstream && |
| 801 | test "$(git config --global remote.pushDefault)" = "origin" && |
| 802 | test "$(git config --local remote.pushDefault)" = "upstream" |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 803 | ) |
Miklos Vajna | bf98421 | 2008-11-03 19:26:18 +0100 | [diff] [blame] | 804 | ' |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 805 | |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 806 | test_expect_success 'rename does not update a non-default fetch refspec' ' |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 807 | git clone one four.one && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 808 | ( |
| 809 | cd four.one && |
| 810 | git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* && |
| 811 | git remote rename origin upstream && |
| 812 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 813 | git rev-parse -q origin/main |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 814 | ) |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 815 | ' |
| 816 | |
| 817 | test_expect_success 'rename a remote with name part of fetch spec' ' |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 818 | git clone one four.two && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 819 | ( |
| 820 | cd four.two && |
| 821 | git remote rename origin remote && |
| 822 | git remote rename remote upstream && |
| 823 | test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*" |
| 824 | ) |
Martin von Zweigbergk | 28f555f | 2011-09-01 20:50:33 -0400 | [diff] [blame] | 825 | ' |
| 826 | |
Martin von Zweigbergk | 60e5eee | 2011-09-01 20:50:34 -0400 | [diff] [blame] | 827 | test_expect_success 'rename a remote with name prefix of other remote' ' |
Martin von Zweigbergk | 60e5eee | 2011-09-01 20:50:34 -0400 | [diff] [blame] | 828 | git clone one four.three && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 829 | ( |
| 830 | cd four.three && |
| 831 | git remote add o git://example.com/repo.git && |
| 832 | git remote rename o upstream && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 833 | test "$(git rev-parse origin/main)" = "$(git rev-parse main)" |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 834 | ) |
Martin von Zweigbergk | 60e5eee | 2011-09-01 20:50:34 -0400 | [diff] [blame] | 835 | ' |
| 836 | |
Johannes Schindelin | e459b07 | 2017-01-19 22:20:02 +0100 | [diff] [blame] | 837 | test_expect_success 'rename succeeds with existing remote.<target>.prune' ' |
Johannes Schindelin | af5bacf | 2017-01-19 22:19:58 +0100 | [diff] [blame] | 838 | git clone one four.four && |
| 839 | test_when_finished git config --global --unset remote.upstream.prune && |
| 840 | git config --global remote.upstream.prune true && |
| 841 | git -C four.four remote rename origin upstream |
| 842 | ' |
| 843 | |
Bert Wesarg | 923d4a5 | 2020-01-27 08:04:30 +0100 | [diff] [blame] | 844 | test_expect_success 'remove a remote' ' |
Bert Wesarg | b3fd6cb | 2020-02-01 10:34:09 +0100 | [diff] [blame] | 845 | test_config_global remote.pushDefault origin && |
Bert Wesarg | 923d4a5 | 2020-01-27 08:04:30 +0100 | [diff] [blame] | 846 | git clone one four.five && |
| 847 | ( |
| 848 | cd four.five && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 849 | git config branch.main.pushRemote origin && |
Bert Wesarg | 923d4a5 | 2020-01-27 08:04:30 +0100 | [diff] [blame] | 850 | git remote remove origin && |
| 851 | test -z "$(git for-each-ref refs/remotes/origin)" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 852 | test_must_fail git config branch.main.remote && |
| 853 | test_must_fail git config branch.main.pushRemote && |
Bert Wesarg | b3fd6cb | 2020-02-01 10:34:09 +0100 | [diff] [blame] | 854 | test "$(git config --global remote.pushDefault)" = "origin" |
| 855 | ) |
| 856 | ' |
| 857 | |
| 858 | test_expect_success 'remove a remote removes repo remote.pushDefault' ' |
| 859 | git clone one four.five.1 && |
| 860 | ( |
| 861 | cd four.five.1 && |
| 862 | git config remote.pushDefault origin && |
| 863 | git remote remove origin && |
| 864 | test_must_fail git config --local remote.pushDefault |
| 865 | ) |
| 866 | ' |
| 867 | |
| 868 | test_expect_success 'remove a remote removes repo remote.pushDefault but ignores global' ' |
| 869 | test_config_global remote.pushDefault other && |
| 870 | git clone one four.five.2 && |
| 871 | ( |
| 872 | cd four.five.2 && |
| 873 | git config remote.pushDefault origin && |
| 874 | git remote remove origin && |
| 875 | test "$(git config --global remote.pushDefault)" = "other" && |
| 876 | test_must_fail git config --local remote.pushDefault |
| 877 | ) |
| 878 | ' |
| 879 | |
| 880 | test_expect_success 'remove a remote removes repo remote.pushDefault but keeps global' ' |
| 881 | test_config_global remote.pushDefault origin && |
| 882 | git clone one four.five.3 && |
| 883 | ( |
| 884 | cd four.five.3 && |
| 885 | git config remote.pushDefault origin && |
| 886 | git remote remove origin && |
| 887 | test "$(git config --global remote.pushDefault)" = "origin" && |
| 888 | test_must_fail git config --local remote.pushDefault |
Bert Wesarg | 923d4a5 | 2020-01-27 08:04:30 +0100 | [diff] [blame] | 889 | ) |
| 890 | ' |
| 891 | |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 892 | cat >remotes_origin <<EOF |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 893 | URL: $(pwd)/one |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 894 | Push: refs/heads/main:refs/heads/upstream |
Ramkumar Ramachandra | f0f249d | 2013-06-22 13:28:18 +0530 | [diff] [blame] | 895 | Push: refs/heads/next:refs/heads/upstream2 |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 896 | Pull: refs/heads/main:refs/heads/origin |
Ramkumar Ramachandra | f0f249d | 2013-06-22 13:28:18 +0530 | [diff] [blame] | 897 | Pull: refs/heads/next:refs/heads/origin2 |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 898 | EOF |
| 899 | |
| 900 | test_expect_success 'migrate a remote from named file in $GIT_DIR/remotes' ' |
| 901 | git clone one five && |
| 902 | origin_url=$(pwd)/one && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 903 | ( |
| 904 | cd five && |
| 905 | git remote remove origin && |
| 906 | mkdir -p .git/remotes && |
| 907 | cat ../remotes_origin >.git/remotes/origin && |
| 908 | git remote rename origin origin && |
Ramkumar Ramachandra | fe3c195 | 2013-06-22 13:28:10 +0530 | [diff] [blame] | 909 | test_path_is_missing .git/remotes/origin && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 910 | test "$(git config remote.origin.url)" = "$origin_url" && |
Ramkumar Ramachandra | f0f249d | 2013-06-22 13:28:18 +0530 | [diff] [blame] | 911 | cat >push_expected <<-\EOF && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 912 | refs/heads/main:refs/heads/upstream |
Ramkumar Ramachandra | f0f249d | 2013-06-22 13:28:18 +0530 | [diff] [blame] | 913 | refs/heads/next:refs/heads/upstream2 |
| 914 | EOF |
| 915 | cat >fetch_expected <<-\EOF && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 916 | refs/heads/main:refs/heads/origin |
Ramkumar Ramachandra | f0f249d | 2013-06-22 13:28:18 +0530 | [diff] [blame] | 917 | refs/heads/next:refs/heads/origin2 |
| 918 | EOF |
| 919 | git config --get-all remote.origin.push >push_actual && |
| 920 | git config --get-all remote.origin.fetch >fetch_actual && |
| 921 | test_cmp push_expected push_actual && |
| 922 | test_cmp fetch_expected fetch_actual |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 923 | ) |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 924 | ' |
| 925 | |
| 926 | test_expect_success 'migrate a remote from named file in $GIT_DIR/branches' ' |
| 927 | git clone one six && |
| 928 | origin_url=$(pwd)/one && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 929 | ( |
| 930 | cd six && |
| 931 | git remote rm origin && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 932 | echo "$origin_url#main" >.git/branches/origin && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 933 | git remote rename origin origin && |
Ramkumar Ramachandra | fe3c195 | 2013-06-22 13:28:10 +0530 | [diff] [blame] | 934 | test_path_is_missing .git/branches/origin && |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 935 | test "$(git config remote.origin.url)" = "$origin_url" && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 936 | test "$(git config remote.origin.fetch)" = "refs/heads/main:refs/heads/origin" && |
| 937 | test "$(git config remote.origin.push)" = "HEAD:refs/heads/main" |
Ramkumar Ramachandra | 9b9439a | 2013-06-22 13:28:08 +0530 | [diff] [blame] | 938 | ) |
Miklos Vajna | 1dd1239 | 2008-11-10 21:43:01 +0100 | [diff] [blame] | 939 | ' |
| 940 | |
Ramkumar Ramachandra | 1f9a5e9 | 2013-06-22 13:28:13 +0530 | [diff] [blame] | 941 | test_expect_success 'migrate a remote from named file in $GIT_DIR/branches (2)' ' |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 942 | git clone one seven && |
| 943 | ( |
Ramkumar Ramachandra | 1f9a5e9 | 2013-06-22 13:28:13 +0530 | [diff] [blame] | 944 | cd seven && |
| 945 | git remote rm origin && |
| 946 | echo "quux#foom" > .git/branches/origin && |
| 947 | git remote rename origin origin && |
| 948 | test_path_is_missing .git/branches/origin && |
| 949 | test "$(git config remote.origin.url)" = "quux" && |
Eric Sunshine | 51b8547 | 2018-07-01 20:24:01 -0400 | [diff] [blame] | 950 | test "$(git config remote.origin.fetch)" = "refs/heads/foom:refs/heads/origin" && |
Ramkumar Ramachandra | 1f9a5e9 | 2013-06-22 13:28:13 +0530 | [diff] [blame] | 951 | test "$(git config remote.origin.push)" = "HEAD:refs/heads/foom" |
| 952 | ) |
| 953 | ' |
| 954 | |
| 955 | test_expect_success 'remote prune to cause a dangling symref' ' |
| 956 | git clone one eight && |
| 957 | ( |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 958 | cd one && |
| 959 | git checkout side2 && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 960 | git branch -D main |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 961 | ) && |
| 962 | ( |
Ramkumar Ramachandra | 1f9a5e9 | 2013-06-22 13:28:13 +0530 | [diff] [blame] | 963 | cd eight && |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 964 | git remote prune origin |
Junio C Hamano | e01de1c | 2010-03-15 22:12:55 -0700 | [diff] [blame] | 965 | ) >err 2>&1 && |
Jiang Xin | f7dc6a9 | 2012-08-27 13:36:54 +0800 | [diff] [blame] | 966 | test_i18ngrep "has become dangling" err && |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 967 | |
Junio C Hamano | e01de1c | 2010-03-15 22:12:55 -0700 | [diff] [blame] | 968 | : And the dangling symref will not cause other annoying errors && |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 969 | ( |
Ramkumar Ramachandra | 1f9a5e9 | 2013-06-22 13:28:13 +0530 | [diff] [blame] | 970 | cd eight && |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 971 | git branch -a |
| 972 | ) 2>err && |
Junio C Hamano | e01de1c | 2010-03-15 22:12:55 -0700 | [diff] [blame] | 973 | ! grep "points nowhere" err && |
Junio C Hamano | 057e713 | 2009-02-08 23:52:01 -0800 | [diff] [blame] | 974 | ( |
Ramkumar Ramachandra | 1f9a5e9 | 2013-06-22 13:28:13 +0530 | [diff] [blame] | 975 | cd eight && |
Junio C Hamano | 057e713 | 2009-02-08 23:52:01 -0800 | [diff] [blame] | 976 | test_must_fail git branch nomore origin |
| 977 | ) 2>err && |
Nguyễn Thái Ngọc Duy | 661558f | 2018-07-21 09:49:35 +0200 | [diff] [blame] | 978 | test_i18ngrep "dangling symref" err |
Junio C Hamano | f8948e2 | 2009-02-08 23:27:10 -0800 | [diff] [blame] | 979 | ' |
| 980 | |
Clemens Buchacher | 6a01554 | 2009-05-27 22:13:43 +0200 | [diff] [blame] | 981 | test_expect_success 'show empty remote' ' |
Clemens Buchacher | 6a01554 | 2009-05-27 22:13:43 +0200 | [diff] [blame] | 982 | test_create_repo empty && |
| 983 | git clone empty empty-clone && |
| 984 | ( |
| 985 | cd empty-clone && |
| 986 | git remote show origin |
| 987 | ) |
| 988 | ' |
| 989 | |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 990 | test_expect_success 'remote set-branches requires a remote' ' |
| 991 | test_must_fail git remote set-branches && |
| 992 | test_must_fail git remote set-branches --add |
| 993 | ' |
| 994 | |
| 995 | test_expect_success 'remote set-branches' ' |
| 996 | echo "+refs/heads/*:refs/remotes/scratch/*" >expect.initial && |
| 997 | sort <<-\EOF >expect.add && |
| 998 | +refs/heads/*:refs/remotes/scratch/* |
| 999 | +refs/heads/other:refs/remotes/scratch/other |
| 1000 | EOF |
| 1001 | sort <<-\EOF >expect.replace && |
| 1002 | +refs/heads/maint:refs/remotes/scratch/maint |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1003 | +refs/heads/main:refs/remotes/scratch/main |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1004 | +refs/heads/next:refs/remotes/scratch/next |
| 1005 | EOF |
| 1006 | sort <<-\EOF >expect.add-two && |
| 1007 | +refs/heads/maint:refs/remotes/scratch/maint |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1008 | +refs/heads/main:refs/remotes/scratch/main |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1009 | +refs/heads/next:refs/remotes/scratch/next |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 1010 | +refs/heads/seen:refs/remotes/scratch/seen |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1011 | +refs/heads/t/topic:refs/remotes/scratch/t/topic |
| 1012 | EOF |
| 1013 | sort <<-\EOF >expect.setup-ffonly && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1014 | refs/heads/main:refs/remotes/scratch/main |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1015 | +refs/heads/next:refs/remotes/scratch/next |
| 1016 | EOF |
| 1017 | sort <<-\EOF >expect.respect-ffonly && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1018 | refs/heads/main:refs/remotes/scratch/main |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1019 | +refs/heads/next:refs/remotes/scratch/next |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 1020 | +refs/heads/seen:refs/remotes/scratch/seen |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1021 | EOF |
| 1022 | |
| 1023 | git clone .git/ setbranches && |
| 1024 | ( |
| 1025 | cd setbranches && |
| 1026 | git remote rename origin scratch && |
| 1027 | git config --get-all remote.scratch.fetch >config-result && |
| 1028 | sort <config-result >../actual.initial && |
| 1029 | |
| 1030 | git remote set-branches scratch --add other && |
| 1031 | git config --get-all remote.scratch.fetch >config-result && |
| 1032 | sort <config-result >../actual.add && |
| 1033 | |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1034 | git remote set-branches scratch maint main next && |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1035 | git config --get-all remote.scratch.fetch >config-result && |
| 1036 | sort <config-result >../actual.replace && |
| 1037 | |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 1038 | git remote set-branches --add scratch seen t/topic && |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1039 | git config --get-all remote.scratch.fetch >config-result && |
| 1040 | sort <config-result >../actual.add-two && |
| 1041 | |
| 1042 | git config --unset-all remote.scratch.fetch && |
| 1043 | git config remote.scratch.fetch \ |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1044 | refs/heads/main:refs/remotes/scratch/main && |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1045 | git config --add remote.scratch.fetch \ |
| 1046 | +refs/heads/next:refs/remotes/scratch/next && |
| 1047 | git config --get-all remote.scratch.fetch >config-result && |
| 1048 | sort <config-result >../actual.setup-ffonly && |
| 1049 | |
Johannes Schindelin | 6dca5db | 2020-06-25 12:18:59 +0000 | [diff] [blame] | 1050 | git remote set-branches --add scratch seen && |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1051 | git config --get-all remote.scratch.fetch >config-result && |
| 1052 | sort <config-result >../actual.respect-ffonly |
| 1053 | ) && |
| 1054 | test_cmp expect.initial actual.initial && |
| 1055 | test_cmp expect.add actual.add && |
| 1056 | test_cmp expect.replace actual.replace && |
| 1057 | test_cmp expect.add-two actual.add-two && |
| 1058 | test_cmp expect.setup-ffonly actual.setup-ffonly && |
| 1059 | test_cmp expect.respect-ffonly actual.respect-ffonly |
| 1060 | ' |
| 1061 | |
| 1062 | test_expect_success 'remote set-branches with --mirror' ' |
| 1063 | echo "+refs/*:refs/*" >expect.initial && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1064 | echo "+refs/heads/main:refs/heads/main" >expect.replace && |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1065 | git clone --mirror .git/ setbranches-mirror && |
| 1066 | ( |
| 1067 | cd setbranches-mirror && |
| 1068 | git remote rename origin scratch && |
| 1069 | git config --get-all remote.scratch.fetch >../actual.initial && |
| 1070 | |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1071 | git remote set-branches scratch heads/main && |
Jonathan Nieder | 3d8b694 | 2010-05-19 13:38:50 -0500 | [diff] [blame] | 1072 | git config --get-all remote.scratch.fetch >../actual.replace |
| 1073 | ) && |
| 1074 | test_cmp expect.initial actual.initial && |
| 1075 | test_cmp expect.replace actual.replace |
| 1076 | ' |
| 1077 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1078 | test_expect_success 'new remote' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1079 | git remote add someremote foo && |
| 1080 | echo foo >expect && |
| 1081 | git config --get-all remote.someremote.url >actual && |
| 1082 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1083 | ' |
Junio C Hamano | 057e713 | 2009-02-08 23:52:01 -0800 | [diff] [blame] | 1084 | |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1085 | get_url_test () { |
| 1086 | cat >expect && |
| 1087 | git remote get-url "$@" >actual && |
| 1088 | test_cmp expect actual |
| 1089 | } |
| 1090 | |
| 1091 | test_expect_success 'get-url on new remote' ' |
| 1092 | echo foo | get_url_test someremote && |
| 1093 | echo foo | get_url_test --all someremote && |
| 1094 | echo foo | get_url_test --push someremote && |
| 1095 | echo foo | get_url_test --push --all someremote |
| 1096 | ' |
| 1097 | |
Patrick Steinhardt | 45ebdcc | 2016-02-22 12:23:28 +0100 | [diff] [blame] | 1098 | test_expect_success 'remote set-url with locked config' ' |
| 1099 | test_when_finished "rm -f .git/config.lock" && |
| 1100 | git config --get-all remote.someremote.url >expect && |
| 1101 | >.git/config.lock && |
| 1102 | test_must_fail git remote set-url someremote baz && |
| 1103 | git config --get-all remote.someremote.url >actual && |
| 1104 | cmp expect actual |
| 1105 | ' |
| 1106 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1107 | test_expect_success 'remote set-url bar' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1108 | git remote set-url someremote bar && |
| 1109 | echo bar >expect && |
| 1110 | git config --get-all remote.someremote.url >actual && |
| 1111 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1112 | ' |
| 1113 | |
| 1114 | test_expect_success 'remote set-url baz bar' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1115 | git remote set-url someremote baz bar && |
| 1116 | echo baz >expect && |
| 1117 | git config --get-all remote.someremote.url >actual && |
| 1118 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1119 | ' |
| 1120 | |
| 1121 | test_expect_success 'remote set-url zot bar' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1122 | test_must_fail git remote set-url someremote zot bar && |
| 1123 | echo baz >expect && |
| 1124 | git config --get-all remote.someremote.url >actual && |
| 1125 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1126 | ' |
| 1127 | |
| 1128 | test_expect_success 'remote set-url --push zot baz' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1129 | test_must_fail git remote set-url --push someremote zot baz && |
| 1130 | echo "YYY" >expect && |
| 1131 | echo baz >>expect && |
| 1132 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1133 | echo "YYY" >>actual && |
| 1134 | git config --get-all remote.someremote.url >>actual && |
| 1135 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1136 | ' |
| 1137 | |
| 1138 | test_expect_success 'remote set-url --push zot' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1139 | git remote set-url --push someremote zot && |
| 1140 | echo zot >expect && |
| 1141 | echo "YYY" >>expect && |
| 1142 | echo baz >>expect && |
| 1143 | git config --get-all remote.someremote.pushurl >actual && |
| 1144 | echo "YYY" >>actual && |
| 1145 | git config --get-all remote.someremote.url >>actual && |
| 1146 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1147 | ' |
| 1148 | |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1149 | test_expect_success 'get-url with different urls' ' |
| 1150 | echo baz | get_url_test someremote && |
| 1151 | echo baz | get_url_test --all someremote && |
| 1152 | echo zot | get_url_test --push someremote && |
| 1153 | echo zot | get_url_test --push --all someremote |
| 1154 | ' |
| 1155 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1156 | test_expect_success 'remote set-url --push qux zot' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1157 | git remote set-url --push someremote qux zot && |
| 1158 | echo qux >expect && |
| 1159 | echo "YYY" >>expect && |
| 1160 | echo baz >>expect && |
| 1161 | git config --get-all remote.someremote.pushurl >actual && |
| 1162 | echo "YYY" >>actual && |
| 1163 | git config --get-all remote.someremote.url >>actual && |
| 1164 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1165 | ' |
| 1166 | |
| 1167 | test_expect_success 'remote set-url --push foo qu+x' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1168 | git remote set-url --push someremote foo qu+x && |
| 1169 | echo foo >expect && |
| 1170 | echo "YYY" >>expect && |
| 1171 | echo baz >>expect && |
| 1172 | git config --get-all remote.someremote.pushurl >actual && |
| 1173 | echo "YYY" >>actual && |
| 1174 | git config --get-all remote.someremote.url >>actual && |
| 1175 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1176 | ' |
| 1177 | |
| 1178 | test_expect_success 'remote set-url --push --add aaa' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1179 | git remote set-url --push --add someremote aaa && |
| 1180 | echo foo >expect && |
| 1181 | echo aaa >>expect && |
| 1182 | echo "YYY" >>expect && |
| 1183 | echo baz >>expect && |
| 1184 | git config --get-all remote.someremote.pushurl >actual && |
| 1185 | echo "YYY" >>actual && |
| 1186 | git config --get-all remote.someremote.url >>actual && |
| 1187 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1188 | ' |
| 1189 | |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1190 | test_expect_success 'get-url on multi push remote' ' |
| 1191 | echo foo | get_url_test --push someremote && |
| 1192 | get_url_test --push --all someremote <<-\EOF |
| 1193 | foo |
| 1194 | aaa |
| 1195 | EOF |
| 1196 | ' |
| 1197 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1198 | test_expect_success 'remote set-url --push bar aaa' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1199 | git remote set-url --push someremote bar aaa && |
| 1200 | echo foo >expect && |
| 1201 | echo bar >>expect && |
| 1202 | echo "YYY" >>expect && |
| 1203 | echo baz >>expect && |
| 1204 | git config --get-all remote.someremote.pushurl >actual && |
| 1205 | echo "YYY" >>actual && |
| 1206 | git config --get-all remote.someremote.url >>actual && |
| 1207 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1208 | ' |
| 1209 | |
| 1210 | test_expect_success 'remote set-url --push --delete bar' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1211 | git remote set-url --push --delete someremote bar && |
| 1212 | echo foo >expect && |
| 1213 | echo "YYY" >>expect && |
| 1214 | echo baz >>expect && |
| 1215 | git config --get-all remote.someremote.pushurl >actual && |
| 1216 | echo "YYY" >>actual && |
| 1217 | git config --get-all remote.someremote.url >>actual && |
| 1218 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1219 | ' |
| 1220 | |
| 1221 | test_expect_success 'remote set-url --push --delete foo' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1222 | git remote set-url --push --delete someremote foo && |
| 1223 | echo "YYY" >expect && |
| 1224 | echo baz >>expect && |
| 1225 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1226 | echo "YYY" >>actual && |
| 1227 | git config --get-all remote.someremote.url >>actual && |
| 1228 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1229 | ' |
| 1230 | |
| 1231 | test_expect_success 'remote set-url --add bbb' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1232 | git remote set-url --add someremote bbb && |
| 1233 | echo "YYY" >expect && |
| 1234 | echo baz >>expect && |
| 1235 | echo bbb >>expect && |
| 1236 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1237 | echo "YYY" >>actual && |
| 1238 | git config --get-all remote.someremote.url >>actual && |
| 1239 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1240 | ' |
| 1241 | |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1242 | test_expect_success 'get-url on multi fetch remote' ' |
| 1243 | echo baz | get_url_test someremote && |
| 1244 | get_url_test --all someremote <<-\EOF |
| 1245 | baz |
| 1246 | bbb |
| 1247 | EOF |
| 1248 | ' |
| 1249 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1250 | test_expect_success 'remote set-url --delete .*' ' |
Brandon Casey | 49de47c | 2010-03-19 19:10:20 -0500 | [diff] [blame] | 1251 | test_must_fail git remote set-url --delete someremote .\* && |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1252 | echo "YYY" >expect && |
| 1253 | echo baz >>expect && |
| 1254 | echo bbb >>expect && |
| 1255 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1256 | echo "YYY" >>actual && |
| 1257 | git config --get-all remote.someremote.url >>actual && |
| 1258 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1259 | ' |
| 1260 | |
| 1261 | test_expect_success 'remote set-url --delete bbb' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1262 | git remote set-url --delete someremote bbb && |
| 1263 | echo "YYY" >expect && |
| 1264 | echo baz >>expect && |
| 1265 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1266 | echo "YYY" >>actual && |
| 1267 | git config --get-all remote.someremote.url >>actual && |
| 1268 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1269 | ' |
| 1270 | |
| 1271 | test_expect_success 'remote set-url --delete baz' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1272 | test_must_fail git remote set-url --delete someremote baz && |
| 1273 | echo "YYY" >expect && |
| 1274 | echo baz >>expect && |
| 1275 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1276 | echo "YYY" >>actual && |
| 1277 | git config --get-all remote.someremote.url >>actual && |
| 1278 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1279 | ' |
| 1280 | |
| 1281 | test_expect_success 'remote set-url --add ccc' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1282 | git remote set-url --add someremote ccc && |
| 1283 | echo "YYY" >expect && |
| 1284 | echo baz >>expect && |
| 1285 | echo ccc >>expect && |
| 1286 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1287 | echo "YYY" >>actual && |
| 1288 | git config --get-all remote.someremote.url >>actual && |
| 1289 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1290 | ' |
| 1291 | |
| 1292 | test_expect_success 'remote set-url --delete baz' ' |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1293 | git remote set-url --delete someremote baz && |
| 1294 | echo "YYY" >expect && |
| 1295 | echo ccc >>expect && |
| 1296 | test_must_fail git config --get-all remote.someremote.pushurl >actual && |
| 1297 | echo "YYY" >>actual && |
| 1298 | git config --get-all remote.someremote.url >>actual && |
| 1299 | cmp expect actual |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1300 | ' |
| 1301 | |
Thomas Rast | abf5f87 | 2013-04-24 15:54:35 +0200 | [diff] [blame] | 1302 | test_expect_success 'extra args: setup' ' |
| 1303 | # add a dummy origin so that this does not trigger failure |
| 1304 | git remote add origin . |
| 1305 | ' |
| 1306 | |
| 1307 | test_extra_arg () { |
Thomas Rast | b17dd3f | 2013-04-24 15:54:37 +0200 | [diff] [blame] | 1308 | test_expect_success "extra args: $*" " |
Thomas Rast | abf5f87 | 2013-04-24 15:54:35 +0200 | [diff] [blame] | 1309 | test_must_fail git remote $* bogus_extra_arg 2>actual && |
Vasco Almeida | 1edbaac | 2016-06-17 20:21:07 +0000 | [diff] [blame] | 1310 | test_i18ngrep '^usage:' actual |
Thomas Rast | abf5f87 | 2013-04-24 15:54:35 +0200 | [diff] [blame] | 1311 | " |
| 1312 | } |
| 1313 | |
Thomas Rast | 2d2e3d2 | 2013-04-24 15:54:36 +0200 | [diff] [blame] | 1314 | test_extra_arg add nick url |
Thomas Rast | abf5f87 | 2013-04-24 15:54:35 +0200 | [diff] [blame] | 1315 | test_extra_arg rename origin newname |
| 1316 | test_extra_arg remove origin |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1317 | test_extra_arg set-head origin main |
Thomas Rast | abf5f87 | 2013-04-24 15:54:35 +0200 | [diff] [blame] | 1318 | # set-branches takes any number of args |
Ben Boeckel | 96f78d3 | 2015-09-15 21:53:47 -0400 | [diff] [blame] | 1319 | test_extra_arg get-url origin newurl |
Thomas Rast | abf5f87 | 2013-04-24 15:54:35 +0200 | [diff] [blame] | 1320 | test_extra_arg set-url origin newurl oldurl |
Thomas Rast | b17dd3f | 2013-04-24 15:54:37 +0200 | [diff] [blame] | 1321 | # show takes any number of args |
| 1322 | # prune takes any number of args |
Thomas Rast | abf5f87 | 2013-04-24 15:54:35 +0200 | [diff] [blame] | 1323 | # update takes any number of args |
| 1324 | |
Johannes Schindelin | b90c95d | 2014-12-23 14:25:09 +0100 | [diff] [blame] | 1325 | test_expect_success 'add remote matching the "insteadOf" URL' ' |
| 1326 | git config url.xyz@example.com.insteadOf backup && |
| 1327 | git remote add backup xyz@example.com |
| 1328 | ' |
| 1329 | |
Ævar Arnfjörð Bjarmason | dd8dd30 | 2018-11-13 19:52:43 +0000 | [diff] [blame] | 1330 | test_expect_success 'unqualified <dst> refspec DWIM and advice' ' |
| 1331 | test_when_finished "(cd test && git tag -d some-tag)" && |
| 1332 | ( |
| 1333 | cd test && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1334 | git tag -a -m "Some tag" some-tag main && |
Ævar Arnfjörð Bjarmason | dd8dd30 | 2018-11-13 19:52:43 +0000 | [diff] [blame] | 1335 | exit_with=true && |
| 1336 | for type in commit tag tree blob |
| 1337 | do |
| 1338 | if test "$type" = "blob" |
| 1339 | then |
| 1340 | oid=$(git rev-parse some-tag:file) |
| 1341 | else |
| 1342 | oid=$(git rev-parse some-tag^{$type}) |
| 1343 | fi && |
| 1344 | test_must_fail git push origin $oid:dst 2>err && |
| 1345 | test_i18ngrep "error: The destination you" err && |
| 1346 | test_i18ngrep "hint: Did you mean" err && |
| 1347 | test_must_fail git -c advice.pushUnqualifiedRefName=false \ |
| 1348 | push origin $oid:dst 2>err && |
| 1349 | test_i18ngrep "error: The destination you" err && |
| 1350 | test_i18ngrep ! "hint: Did you mean" err || |
| 1351 | exit_with=false |
| 1352 | done && |
| 1353 | $exit_with |
| 1354 | ) |
| 1355 | ' |
| 1356 | |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1357 | test_expect_success 'refs/remotes/* <src> refspec and unqualified <dst> DWIM and advice' ' |
Ævar Arnfjörð Bjarmason | bf70636 | 2018-11-13 19:52:44 +0000 | [diff] [blame] | 1358 | ( |
| 1359 | cd two && |
Johannes Schindelin | 97b9136 | 2020-12-17 01:07:05 +0000 | [diff] [blame] | 1360 | git tag -a -m "Some tag" my-tag main && |
Ævar Arnfjörð Bjarmason | bf70636 | 2018-11-13 19:52:44 +0000 | [diff] [blame] | 1361 | git update-ref refs/trees/my-head-tree HEAD^{tree} && |
| 1362 | git update-ref refs/blobs/my-file-blob HEAD:file |
| 1363 | ) && |
| 1364 | ( |
| 1365 | cd test && |
| 1366 | git config --add remote.two.fetch "+refs/tags/*:refs/remotes/tags-from-two/*" && |
| 1367 | git config --add remote.two.fetch "+refs/trees/*:refs/remotes/trees-from-two/*" && |
| 1368 | git config --add remote.two.fetch "+refs/blobs/*:refs/remotes/blobs-from-two/*" && |
| 1369 | git fetch --no-tags two && |
| 1370 | |
| 1371 | test_must_fail git push origin refs/remotes/two/another:dst 2>err && |
| 1372 | test_i18ngrep "error: The destination you" err && |
| 1373 | |
| 1374 | test_must_fail git push origin refs/remotes/tags-from-two/my-tag:dst-tag 2>err && |
| 1375 | test_i18ngrep "error: The destination you" err && |
| 1376 | |
| 1377 | test_must_fail git push origin refs/remotes/trees-from-two/my-head-tree:dst-tree 2>err && |
| 1378 | test_i18ngrep "error: The destination you" err && |
| 1379 | |
| 1380 | test_must_fail git push origin refs/remotes/blobs-from-two/my-file-blob:dst-blob 2>err && |
| 1381 | test_i18ngrep "error: The destination you" err |
| 1382 | ) |
| 1383 | ' |
Ævar Arnfjörð Bjarmason | dd8dd30 | 2018-11-13 19:52:43 +0000 | [diff] [blame] | 1384 | |
Ilari Liusvaara | 433f2be | 2010-01-18 19:18:02 +0200 | [diff] [blame] | 1385 | test_done |