Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='compare & swap push force/delete safety' |
| 4 | |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +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 | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | setup_srcdst_basic () { |
| 11 | rm -fr src dst && |
| 12 | git clone --no-local . src && |
| 13 | git clone --no-local src dst && |
| 14 | ( |
| 15 | cd src && git checkout HEAD^0 |
| 16 | ) |
| 17 | } |
| 18 | |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 19 | # For tests with "--force-if-includes". |
| 20 | setup_src_dup_dst () { |
| 21 | rm -fr src dup dst && |
| 22 | git init --bare dst && |
| 23 | git clone --no-local dst src && |
| 24 | git clone --no-local dst dup |
| 25 | ( |
| 26 | cd src && |
| 27 | test_commit A && |
| 28 | test_commit B && |
| 29 | test_commit C && |
| 30 | git push origin |
| 31 | ) && |
| 32 | ( |
| 33 | cd dup && |
| 34 | git fetch && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 35 | git merge origin/main && |
| 36 | git switch -c branch main~2 && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 37 | test_commit D && |
| 38 | test_commit E && |
| 39 | git push origin --all |
| 40 | ) && |
| 41 | ( |
| 42 | cd src && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 43 | git switch main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 44 | git fetch --all && |
| 45 | git branch branch --track origin/branch && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 46 | git rebase origin/main |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 47 | ) && |
| 48 | ( |
| 49 | cd dup && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 50 | git switch main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 51 | test_commit F && |
| 52 | test_commit G && |
| 53 | git switch branch && |
| 54 | test_commit H && |
| 55 | git push origin --all |
| 56 | ) |
| 57 | } |
| 58 | |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 59 | test_expect_success setup ' |
Jeff King | 53350a3 | 2015-03-20 06:12:37 -0400 | [diff] [blame] | 60 | # create template repository |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 61 | test_commit A && |
| 62 | test_commit B && |
| 63 | test_commit C |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'push to update (protected)' ' |
| 67 | setup_srcdst_basic && |
| 68 | ( |
| 69 | cd dst && |
| 70 | test_commit D && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 71 | test_must_fail git push --force-with-lease=main:main origin main 2>err && |
Andrew Wheeler | b2e93f8 | 2016-01-29 17:18:42 -0600 | [diff] [blame] | 72 | grep "stale info" err |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 73 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 74 | git ls-remote . refs/heads/main >expect && |
| 75 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 76 | test_cmp expect actual |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'push to update (protected, forced)' ' |
| 80 | setup_srcdst_basic && |
| 81 | ( |
| 82 | cd dst && |
| 83 | test_commit D && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 84 | git push --force --force-with-lease=main:main origin main 2>err && |
Andrew Wheeler | b2e93f8 | 2016-01-29 17:18:42 -0600 | [diff] [blame] | 85 | grep "forced update" err |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 86 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 87 | git ls-remote dst refs/heads/main >expect && |
| 88 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 89 | test_cmp expect actual |
| 90 | ' |
| 91 | |
| 92 | test_expect_success 'push to update (protected, tracking)' ' |
| 93 | setup_srcdst_basic && |
| 94 | ( |
| 95 | cd src && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 96 | git checkout main && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 97 | test_commit D && |
| 98 | git checkout HEAD^0 |
| 99 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 100 | git ls-remote src refs/heads/main >expect && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 101 | ( |
| 102 | cd dst && |
| 103 | test_commit E && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 104 | git ls-remote . refs/remotes/origin/main >expect && |
| 105 | test_must_fail git push --force-with-lease=main origin main && |
| 106 | git ls-remote . refs/remotes/origin/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 107 | test_cmp expect actual |
| 108 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 109 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 110 | test_cmp expect actual |
| 111 | ' |
| 112 | |
| 113 | test_expect_success 'push to update (protected, tracking, forced)' ' |
| 114 | setup_srcdst_basic && |
| 115 | ( |
| 116 | cd src && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 117 | git checkout main && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 118 | test_commit D && |
| 119 | git checkout HEAD^0 |
| 120 | ) && |
| 121 | ( |
| 122 | cd dst && |
| 123 | test_commit E && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 124 | git ls-remote . refs/remotes/origin/main >expect && |
| 125 | git push --force --force-with-lease=main origin main |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 126 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 127 | git ls-remote dst refs/heads/main >expect && |
| 128 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 129 | test_cmp expect actual |
| 130 | ' |
| 131 | |
| 132 | test_expect_success 'push to update (allowed)' ' |
| 133 | setup_srcdst_basic && |
| 134 | ( |
| 135 | cd dst && |
| 136 | test_commit D && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 137 | git push --force-with-lease=main:main^ origin main |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 138 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 139 | git ls-remote dst refs/heads/main >expect && |
| 140 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 141 | test_cmp expect actual |
| 142 | ' |
| 143 | |
| 144 | test_expect_success 'push to update (allowed, tracking)' ' |
| 145 | setup_srcdst_basic && |
| 146 | ( |
| 147 | cd dst && |
| 148 | test_commit D && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 149 | git push --force-with-lease=main origin main 2>err && |
Andrew Wheeler | b2e93f8 | 2016-01-29 17:18:42 -0600 | [diff] [blame] | 150 | ! grep "forced update" err |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 151 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 152 | git ls-remote dst refs/heads/main >expect && |
| 153 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 154 | test_cmp expect actual |
| 155 | ' |
| 156 | |
| 157 | test_expect_success 'push to update (allowed even though no-ff)' ' |
| 158 | setup_srcdst_basic && |
| 159 | ( |
| 160 | cd dst && |
| 161 | git reset --hard HEAD^ && |
| 162 | test_commit D && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 163 | git push --force-with-lease=main origin main 2>err && |
Andrew Wheeler | b2e93f8 | 2016-01-29 17:18:42 -0600 | [diff] [blame] | 164 | grep "forced update" err |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 165 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 166 | git ls-remote dst refs/heads/main >expect && |
| 167 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 168 | test_cmp expect actual |
| 169 | ' |
| 170 | |
| 171 | test_expect_success 'push to delete (protected)' ' |
| 172 | setup_srcdst_basic && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 173 | git ls-remote src refs/heads/main >expect && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 174 | ( |
| 175 | cd dst && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 176 | test_must_fail git push --force-with-lease=main:main^ origin :main |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 177 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 178 | git ls-remote src refs/heads/main >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 179 | test_cmp expect actual |
| 180 | ' |
| 181 | |
| 182 | test_expect_success 'push to delete (protected, forced)' ' |
| 183 | setup_srcdst_basic && |
| 184 | ( |
| 185 | cd dst && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 186 | git push --force --force-with-lease=main:main^ origin :main |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 187 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 188 | git ls-remote src refs/heads/main >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 189 | test_must_be_empty actual |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 190 | ' |
| 191 | |
| 192 | test_expect_success 'push to delete (allowed)' ' |
| 193 | setup_srcdst_basic && |
| 194 | ( |
| 195 | cd dst && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 196 | git push --force-with-lease=main origin :main 2>err && |
Andrew Wheeler | b2e93f8 | 2016-01-29 17:18:42 -0600 | [diff] [blame] | 197 | grep deleted err |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 198 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 199 | git ls-remote src refs/heads/main >actual && |
Ævar Arnfjörð Bjarmason | d3c6751 | 2018-07-27 17:48:11 +0000 | [diff] [blame] | 200 | test_must_be_empty actual |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 201 | ' |
| 202 | |
| 203 | test_expect_success 'cover everything with default force-with-lease (protected)' ' |
| 204 | setup_srcdst_basic && |
| 205 | ( |
| 206 | cd src && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 207 | git branch nain main^ |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 208 | ) && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 209 | git ls-remote src refs/heads/\* >expect && |
| 210 | ( |
| 211 | cd dst && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 212 | test_must_fail git push --force-with-lease origin main main:nain |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 213 | ) && |
| 214 | git ls-remote src refs/heads/\* >actual && |
| 215 | test_cmp expect actual |
| 216 | ' |
| 217 | |
| 218 | test_expect_success 'cover everything with default force-with-lease (allowed)' ' |
| 219 | setup_srcdst_basic && |
| 220 | ( |
| 221 | cd src && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 222 | git branch nain main^ |
Jeff King | 99094a7 | 2015-03-20 06:07:15 -0400 | [diff] [blame] | 223 | ) && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 224 | ( |
| 225 | cd dst && |
| 226 | git fetch && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 227 | git push --force-with-lease origin main main:nain |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 228 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 229 | git ls-remote dst refs/heads/main | |
| 230 | sed -e "s/main/nain/" >expect && |
| 231 | git ls-remote src refs/heads/nain >actual && |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 232 | test_cmp expect actual |
| 233 | ' |
| 234 | |
John Keeping | 64ac39a | 2016-07-26 21:44:45 +0100 | [diff] [blame] | 235 | test_expect_success 'new branch covered by force-with-lease' ' |
| 236 | setup_srcdst_basic && |
| 237 | ( |
| 238 | cd dst && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 239 | git branch branch main && |
John Keeping | 64ac39a | 2016-07-26 21:44:45 +0100 | [diff] [blame] | 240 | git push --force-with-lease=branch origin branch |
| 241 | ) && |
| 242 | git ls-remote dst refs/heads/branch >expect && |
| 243 | git ls-remote src refs/heads/branch >actual && |
| 244 | test_cmp expect actual |
| 245 | ' |
| 246 | |
John Keeping | eee98e7 | 2016-07-26 21:44:44 +0100 | [diff] [blame] | 247 | test_expect_success 'new branch covered by force-with-lease (explicit)' ' |
| 248 | setup_srcdst_basic && |
| 249 | ( |
| 250 | cd dst && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 251 | git branch branch main && |
John Keeping | eee98e7 | 2016-07-26 21:44:44 +0100 | [diff] [blame] | 252 | git push --force-with-lease=branch: origin branch |
| 253 | ) && |
| 254 | git ls-remote dst refs/heads/branch >expect && |
| 255 | git ls-remote src refs/heads/branch >actual && |
| 256 | test_cmp expect actual |
| 257 | ' |
| 258 | |
| 259 | test_expect_success 'new branch already exists' ' |
| 260 | setup_srcdst_basic && |
| 261 | ( |
| 262 | cd src && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 263 | git checkout -b branch main && |
Johannes Schindelin | 9eed4f3 | 2016-08-04 16:54:35 +0200 | [diff] [blame] | 264 | test_commit F |
John Keeping | eee98e7 | 2016-07-26 21:44:44 +0100 | [diff] [blame] | 265 | ) && |
| 266 | ( |
| 267 | cd dst && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 268 | git branch branch main && |
John Keeping | eee98e7 | 2016-07-26 21:44:44 +0100 | [diff] [blame] | 269 | test_must_fail git push --force-with-lease=branch: origin branch |
| 270 | ) |
| 271 | ' |
| 272 | |
Ævar Arnfjörð Bjarmason | f17d642 | 2017-04-19 09:22:03 +0000 | [diff] [blame] | 273 | test_expect_success 'background updates of REMOTE can be mitigated with a non-updated REMOTE-push' ' |
| 274 | rm -rf src dst && |
| 275 | git init --bare src.bare && |
| 276 | test_when_finished "rm -rf src.bare" && |
| 277 | git clone --no-local src.bare dst && |
| 278 | test_when_finished "rm -rf dst" && |
| 279 | ( |
| 280 | cd dst && |
| 281 | test_commit G && |
| 282 | git remote add origin-push ../src.bare && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 283 | git push origin-push main:main |
Ævar Arnfjörð Bjarmason | f17d642 | 2017-04-19 09:22:03 +0000 | [diff] [blame] | 284 | ) && |
| 285 | git clone --no-local src.bare dst2 && |
| 286 | test_when_finished "rm -rf dst2" && |
| 287 | ( |
| 288 | cd dst2 && |
| 289 | test_commit H && |
| 290 | git push |
| 291 | ) && |
| 292 | ( |
| 293 | cd dst && |
| 294 | test_commit I && |
| 295 | git fetch origin && |
| 296 | test_must_fail git push --force-with-lease origin-push && |
| 297 | git fetch origin-push && |
| 298 | git push --force-with-lease origin-push |
| 299 | ) |
| 300 | ' |
| 301 | |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 302 | test_expect_success 'background updates to remote can be mitigated with "--force-if-includes"' ' |
| 303 | setup_src_dup_dst && |
| 304 | test_when_finished "rm -fr dst src dup" && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 305 | git ls-remote dst refs/heads/main >expect.main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 306 | git ls-remote dst refs/heads/branch >expect.branch && |
| 307 | ( |
| 308 | cd src && |
| 309 | git switch branch && |
| 310 | test_commit I && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 311 | git switch main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 312 | test_commit J && |
| 313 | git fetch --all && |
| 314 | test_must_fail git push --force-with-lease --force-if-includes --all |
| 315 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 316 | git ls-remote dst refs/heads/main >actual.main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 317 | git ls-remote dst refs/heads/branch >actual.branch && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 318 | test_cmp expect.main actual.main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 319 | test_cmp expect.branch actual.branch |
| 320 | ' |
| 321 | |
| 322 | test_expect_success 'background updates to remote can be mitigated with "push.useForceIfIncludes"' ' |
| 323 | setup_src_dup_dst && |
| 324 | test_when_finished "rm -fr dst src dup" && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 325 | git ls-remote dst refs/heads/main >expect.main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 326 | ( |
| 327 | cd src && |
| 328 | git switch branch && |
| 329 | test_commit I && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 330 | git switch main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 331 | test_commit J && |
| 332 | git fetch --all && |
| 333 | git config --local push.useForceIfIncludes true && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 334 | test_must_fail git push --force-with-lease=main origin main |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 335 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 336 | git ls-remote dst refs/heads/main >actual.main && |
| 337 | test_cmp expect.main actual.main |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 338 | ' |
| 339 | |
| 340 | test_expect_success '"--force-if-includes" should be disabled for --force-with-lease="<refname>:<expect>"' ' |
| 341 | setup_src_dup_dst && |
| 342 | test_when_finished "rm -fr dst src dup" && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 343 | git ls-remote dst refs/heads/main >expect.main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 344 | ( |
| 345 | cd src && |
| 346 | git switch branch && |
| 347 | test_commit I && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 348 | git switch main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 349 | test_commit J && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 350 | remote_head="$(git rev-parse refs/remotes/origin/main)" && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 351 | git fetch --all && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 352 | test_must_fail git push --force-if-includes --force-with-lease="main:$remote_head" 2>err && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 353 | grep "stale info" err |
| 354 | ) && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 355 | git ls-remote dst refs/heads/main >actual.main && |
| 356 | test_cmp expect.main actual.main |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 357 | ' |
| 358 | |
| 359 | test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase")' ' |
| 360 | setup_src_dup_dst && |
| 361 | test_when_finished "rm -fr dst src dup" && |
| 362 | ( |
| 363 | cd src && |
| 364 | git switch branch && |
| 365 | test_commit I && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 366 | git switch main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 367 | test_commit J && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 368 | git pull --rebase origin main && |
| 369 | git push --force-if-includes --force-with-lease="main" |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 370 | ) |
| 371 | ' |
| 372 | |
| 373 | test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase", local rebase)' ' |
| 374 | setup_src_dup_dst && |
| 375 | test_when_finished "rm -fr dst src dup" && |
| 376 | ( |
| 377 | cd src && |
| 378 | git switch branch && |
| 379 | test_commit I && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 380 | git switch main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 381 | test_commit J && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 382 | git pull --rebase origin main && |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 383 | git rebase --onto HEAD~4 HEAD~1 && |
Johannes Schindelin | 3ac8f63 | 2020-11-18 23:44:33 +0000 | [diff] [blame] | 384 | git push --force-if-includes --force-with-lease="main" |
Srinidhi Kaushik | 3b5bf96 | 2020-10-03 17:40:46 +0530 | [diff] [blame] | 385 | ) |
| 386 | ' |
| 387 | |
| 388 | test_expect_success '"--force-if-includes" should allow deletes' ' |
| 389 | setup_src_dup_dst && |
| 390 | test_when_finished "rm -fr dst src dup" && |
| 391 | ( |
| 392 | cd src && |
| 393 | git switch branch && |
| 394 | git pull --rebase origin branch && |
| 395 | git push --force-if-includes --force-with-lease="branch" origin :branch |
| 396 | ) |
| 397 | ' |
| 398 | |
Junio C Hamano | d887cc1 | 2013-07-09 12:09:28 -0700 | [diff] [blame] | 399 | test_done |