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