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