| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='basic rebase topology tests' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | . "$TEST_DIRECTORY"/lib-rebase.sh |
| 7 | |
| 8 | # a---b---c |
| 9 | # \ |
| 10 | # d---e |
| 11 | test_expect_success 'setup' ' |
| 12 | test_commit a && |
| 13 | test_commit b && |
| 14 | test_commit c && |
| 15 | git checkout b && |
| 16 | test_commit d && |
| 17 | test_commit e |
| 18 | ' |
| 19 | |
| 20 | test_run_rebase () { |
| 21 | result=$1 |
| 22 | shift |
| 23 | test_expect_$result "simple rebase $*" " |
| 24 | reset_rebase && |
| 25 | git rebase $* c e && |
| 26 | test_cmp_rev c HEAD~2 && |
| 27 | test_linear_range 'd e' c.. |
| 28 | " |
| 29 | } |
| 30 | test_run_rebase success --apply |
| 31 | test_run_rebase success -m |
| 32 | test_run_rebase success -i |
| 33 | |
| 34 | test_expect_success 'setup branches and remote tracking' ' |
| 35 | git tag -l >tags && |
| 36 | for tag in $(cat tags) |
| 37 | do |
| 38 | git branch branch-$tag $tag || return 1 |
| 39 | done && |
| 40 | git remote add origin "file://$PWD" && |
| 41 | git fetch origin |
| 42 | ' |
| 43 | |
| 44 | test_run_rebase () { |
| 45 | result=$1 |
| 46 | shift |
| 47 | test_expect_$result "rebase $* is no-op if upstream is an ancestor" " |
| 48 | reset_rebase && |
| 49 | git rebase $* b e && |
| 50 | test_cmp_rev e HEAD |
| 51 | " |
| 52 | } |
| 53 | test_run_rebase success --apply |
| 54 | test_run_rebase success -m |
| 55 | test_run_rebase success -i |
| 56 | |
| 57 | test_run_rebase () { |
| 58 | result=$1 |
| 59 | shift |
| 60 | test_expect_$result "rebase $* -f rewrites even if upstream is an ancestor" " |
| 61 | reset_rebase && |
| 62 | git rebase $* -f b e && |
| 63 | test_cmp_rev ! e HEAD && |
| 64 | test_cmp_rev b HEAD~2 && |
| 65 | test_linear_range 'd e' b.. |
| 66 | " |
| 67 | } |
| 68 | test_run_rebase success --apply |
| 69 | test_run_rebase success --fork-point |
| 70 | test_run_rebase success -m |
| 71 | test_run_rebase success -i |
| 72 | |
| 73 | test_run_rebase () { |
| 74 | result=$1 |
| 75 | shift |
| 76 | test_expect_$result "rebase $* -f rewrites even if remote upstream is an ancestor" " |
| 77 | reset_rebase && |
| 78 | git rebase $* -f branch-b branch-e && |
| 79 | test_cmp_rev ! branch-e origin/branch-e && |
| 80 | test_cmp_rev branch-b HEAD~2 && |
| 81 | test_linear_range 'd e' branch-b.. |
| 82 | " |
| 83 | } |
| 84 | test_run_rebase success --apply |
| 85 | test_run_rebase success --fork-point |
| 86 | test_run_rebase success -m |
| 87 | test_run_rebase success -i |
| 88 | |
| 89 | test_run_rebase () { |
| 90 | result=$1 |
| 91 | shift |
| 92 | test_expect_$result "rebase $* fast-forwards from ancestor of upstream" " |
| 93 | reset_rebase && |
| 94 | git rebase $* e b && |
| 95 | test_cmp_rev e HEAD |
| 96 | " |
| 97 | } |
| 98 | test_run_rebase success --apply |
| 99 | test_run_rebase success --fork-point |
| 100 | test_run_rebase success -m |
| 101 | test_run_rebase success -i |
| 102 | |
| 103 | # f |
| 104 | # / |
| 105 | # a---b---c---g---h |
| 106 | # \ |
| 107 | # d---gp--i |
| 108 | # |
| 109 | # gp = cherry-picked g |
| 110 | # h = reverted g |
| 111 | # |
| 112 | # Reverted patches are there for tests to be able to check if a commit |
| 113 | # that introduced the same change as another commit is |
| 114 | # dropped. Without reverted commits, we could get false positives |
| 115 | # because applying the patch succeeds, but simply results in no |
| 116 | # changes. |
| 117 | test_expect_success 'setup of linear history for range selection tests' ' |
| 118 | git checkout c && |
| 119 | test_commit g && |
| 120 | revert h g && |
| 121 | git checkout d && |
| 122 | cherry_pick gp g && |
| 123 | test_commit i && |
| 124 | git checkout b && |
| 125 | test_commit f |
| 126 | ' |
| 127 | |
| 128 | test_run_rebase () { |
| 129 | result=$1 |
| 130 | shift |
| 131 | test_expect_$result "rebase $* drops patches in upstream" " |
| 132 | reset_rebase && |
| 133 | git rebase $* h i && |
| 134 | test_cmp_rev h HEAD~2 && |
| 135 | test_linear_range 'd i' h.. |
| 136 | " |
| 137 | } |
| 138 | test_run_rebase success --apply |
| 139 | test_run_rebase success -m |
| 140 | test_run_rebase success -i |
| 141 | |
| 142 | test_run_rebase () { |
| 143 | result=$1 |
| 144 | shift |
| 145 | test_expect_$result "rebase $* can drop last patch if in upstream" " |
| 146 | reset_rebase && |
| 147 | git rebase $* h gp && |
| 148 | test_cmp_rev h HEAD^ && |
| 149 | test_linear_range 'd' h.. |
| 150 | " |
| 151 | } |
| 152 | test_run_rebase success --apply |
| 153 | test_run_rebase success -m |
| 154 | test_run_rebase success -i |
| 155 | |
| 156 | test_run_rebase () { |
| 157 | result=$1 |
| 158 | shift |
| 159 | test_expect_$result "rebase $* --onto drops patches in upstream" " |
| 160 | reset_rebase && |
| 161 | git rebase $* --onto f h i && |
| 162 | test_cmp_rev f HEAD~2 && |
| 163 | test_linear_range 'd i' f.. |
| 164 | " |
| 165 | } |
| 166 | test_run_rebase success --apply |
| 167 | test_run_rebase success -m |
| 168 | test_run_rebase success -i |
| 169 | |
| 170 | test_run_rebase () { |
| 171 | result=$1 |
| 172 | shift |
| 173 | test_expect_$result "rebase $* --onto does not drop patches in onto" " |
| 174 | reset_rebase && |
| 175 | git rebase $* --onto h f i && |
| 176 | test_cmp_rev h HEAD~3 && |
| 177 | test_linear_range 'd gp i' h.. |
| 178 | " |
| 179 | } |
| 180 | test_run_rebase success --apply |
| 181 | test_run_rebase success -m |
| 182 | test_run_rebase success -i |
| 183 | |
| 184 | # a---b---c---j! |
| 185 | # \ |
| 186 | # d---k!--l |
| 187 | # |
| 188 | # ! = empty |
| 189 | test_expect_success 'setup of linear history for empty commit tests' ' |
| 190 | git checkout c && |
| 191 | make_empty j && |
| 192 | git checkout d && |
| 193 | make_empty k && |
| 194 | test_commit l |
| 195 | ' |
| 196 | |
| 197 | test_run_rebase () { |
| 198 | result=$1 |
| 199 | shift |
| 200 | test_expect_$result "rebase $* keeps begin-empty commits" " |
| 201 | reset_rebase && |
| 202 | git rebase $* j l && |
| 203 | test_cmp_rev c HEAD~4 && |
| 204 | test_linear_range 'j d k l' c.. |
| 205 | " |
| 206 | } |
| 207 | test_run_rebase failure --apply |
| 208 | test_run_rebase success -m |
| 209 | test_run_rebase success -i |
| 210 | |
| 211 | test_run_rebase () { |
| 212 | result=$1 |
| 213 | shift |
| 214 | test_expect_$result "rebase $* --no-keep-empty drops begin-empty commits" " |
| 215 | reset_rebase && |
| 216 | git rebase $* --no-keep-empty c l && |
| 217 | test_cmp_rev c HEAD~2 && |
| 218 | test_linear_range 'd l' c.. |
| 219 | " |
| 220 | } |
| 221 | test_run_rebase success -m |
| 222 | test_run_rebase success -i |
| 223 | |
| 224 | test_run_rebase () { |
| 225 | result=$1 |
| 226 | shift |
| 227 | test_expect_$result "rebase $* --keep-empty keeps empty even if already in upstream" " |
| 228 | reset_rebase && |
| 229 | git rebase $* --keep-empty j l && |
| 230 | test_cmp_rev j HEAD~3 && |
| 231 | test_linear_range 'd k l' j.. |
| 232 | " |
| 233 | } |
| 234 | test_run_rebase success -m |
| 235 | test_run_rebase success -i |
| 236 | test_run_rebase success --rebase-merges |
| 237 | |
| 238 | # m |
| 239 | # / |
| 240 | # a---b---c---g |
| 241 | # |
| 242 | # x---y---bp |
| 243 | # |
| 244 | # bp = cherry-picked b |
| 245 | # m = reverted b |
| 246 | # |
| 247 | # Reverted patches are there for tests to be able to check if a commit |
| 248 | # that introduced the same change as another commit is |
| 249 | # dropped. Without reverted commits, we could get false positives |
| 250 | # because applying the patch succeeds, but simply results in no |
| 251 | # changes. |
| 252 | test_expect_success 'setup of linear history for test involving root' ' |
| 253 | git checkout b && |
| 254 | revert m b && |
| 255 | git checkout --orphan disjoint && |
| 256 | git rm -rf . && |
| 257 | test_commit x && |
| 258 | test_commit y && |
| 259 | cherry_pick bp b |
| 260 | ' |
| 261 | |
| 262 | test_run_rebase () { |
| 263 | result=$1 |
| 264 | shift |
| 265 | test_expect_$result "rebase $* --onto --root" " |
| 266 | reset_rebase && |
| 267 | git rebase $* --onto c --root y && |
| 268 | test_cmp_rev c HEAD~2 && |
| 269 | test_linear_range 'x y' c.. |
| 270 | " |
| 271 | } |
| 272 | test_run_rebase success --apply |
| 273 | test_run_rebase success -m |
| 274 | test_run_rebase success -i |
| 275 | |
| 276 | test_run_rebase () { |
| 277 | result=$1 |
| 278 | shift |
| 279 | test_expect_$result "rebase $* without --onto --root with disjoint history" " |
| 280 | reset_rebase && |
| 281 | git rebase $* c y && |
| 282 | test_cmp_rev c HEAD~2 && |
| 283 | test_linear_range 'x y' c.. |
| 284 | " |
| 285 | } |
| 286 | test_run_rebase success --apply |
| 287 | test_run_rebase success -m |
| 288 | test_run_rebase success -i |
| 289 | |
| 290 | test_run_rebase () { |
| 291 | result=$1 |
| 292 | shift |
| 293 | test_expect_$result "rebase $* --onto --root drops patch in onto" " |
| 294 | reset_rebase && |
| 295 | git rebase $* --onto m --root bp && |
| 296 | test_cmp_rev m HEAD~2 && |
| 297 | test_linear_range 'x y' m.. |
| 298 | " |
| 299 | } |
| 300 | test_run_rebase success --apply |
| 301 | test_run_rebase success -m |
| 302 | test_run_rebase success -i |
| 303 | |
| 304 | test_run_rebase () { |
| 305 | result=$1 |
| 306 | shift |
| 307 | test_expect_$result "rebase $* --onto --root with merge-base does not go to root" " |
| 308 | reset_rebase && |
| 309 | git rebase $* --onto m --root g && |
| 310 | test_cmp_rev m HEAD~2 && |
| 311 | test_linear_range 'c g' m.. |
| 312 | " |
| 313 | } |
| 314 | |
| 315 | test_run_rebase success --apply |
| 316 | test_run_rebase success -m |
| 317 | test_run_rebase success -i |
| 318 | |
| 319 | test_run_rebase () { |
| 320 | result=$1 |
| 321 | shift |
| 322 | test_expect_$result "rebase $* without --onto --root with disjoint history drops patch in onto" " |
| 323 | reset_rebase && |
| 324 | git rebase $* m bp && |
| 325 | test_cmp_rev m HEAD~2 && |
| 326 | test_linear_range 'x y' m.. |
| 327 | " |
| 328 | } |
| 329 | test_run_rebase success --apply |
| 330 | test_run_rebase success -m |
| 331 | test_run_rebase success -i |
| 332 | |
| 333 | test_run_rebase () { |
| 334 | result=$1 |
| 335 | shift |
| 336 | test_expect_$result "rebase $* --root on linear history is a no-op" " |
| 337 | reset_rebase && |
| 338 | git rebase $* --root c && |
| 339 | test_cmp_rev c HEAD |
| 340 | " |
| 341 | } |
| 342 | test_run_rebase success '' |
| 343 | test_run_rebase success -m |
| 344 | test_run_rebase success -i |
| 345 | |
| 346 | test_run_rebase () { |
| 347 | result=$1 |
| 348 | shift |
| 349 | test_expect_$result "rebase $* -f --root on linear history causes re-write" " |
| 350 | reset_rebase && |
| 351 | git rebase $* -f --root c && |
| 352 | test_cmp_rev ! a HEAD~2 && |
| 353 | test_linear_range 'a b c' HEAD |
| 354 | " |
| 355 | } |
| 356 | test_run_rebase success '' |
| 357 | test_run_rebase success -m |
| 358 | test_run_rebase success -i |
| 359 | |
| 360 | test_done |