t / t3425-rebase-topology-merges.shon commit diff-parseopt: restore -U (no argument) behavior (8ef0519)
   1#!/bin/sh
   2
   3test_description='rebase topology tests with merges'
   4. ./test-lib.sh
   5. "$TEST_DIRECTORY"/lib-rebase.sh
   6
   7test_revision_subjects () {
   8        expected="$1"
   9        shift
  10        set -- $(git log --format=%s --no-walk=unsorted "$@")
  11        test "$expected" = "$*"
  12}
  13
  14# a---b-----------c
  15#      \           \
  16#       d-------e   \
  17#        \       \   \
  18#         n---o---w---v
  19#              \
  20#               z
  21test_expect_success 'setup of non-linear-history' '
  22        test_commit a &&
  23        test_commit b &&
  24        test_commit c &&
  25        git checkout b &&
  26        test_commit d &&
  27        test_commit e &&
  28
  29        git checkout c &&
  30        test_commit g &&
  31        revert h g &&
  32        git checkout d &&
  33        cherry_pick gp g &&
  34        test_commit i &&
  35        git checkout b &&
  36        test_commit f &&
  37
  38        git checkout d &&
  39        test_commit n &&
  40        test_commit o &&
  41        test_merge w e &&
  42        test_merge v c &&
  43        git checkout o &&
  44        test_commit z
  45'
  46
  47test_run_rebase () {
  48        result=$1
  49        shift
  50        test_expect_$result "rebase $* after merge from upstream" "
  51                reset_rebase &&
  52                git rebase $* e w &&
  53                test_cmp_rev e HEAD~2 &&
  54                test_linear_range 'n o' e..
  55        "
  56}
  57test_run_rebase success ''
  58test_run_rebase success -m
  59test_run_rebase success -i
  60
  61test_run_rebase () {
  62        result=$1
  63        shift
  64        expected=$1
  65        shift
  66        test_expect_$result "rebase $* of non-linear history is linearized in place" "
  67                reset_rebase &&
  68                git rebase $* d w &&
  69                test_cmp_rev d HEAD~3 &&
  70                test_linear_range "\'"$expected"\'" d..
  71        "
  72}
  73#TODO: make order consistent across all flavors of rebase
  74test_run_rebase success 'e n o' ''
  75test_run_rebase success 'e n o' -m
  76test_run_rebase success 'n o e' -i
  77
  78test_run_rebase () {
  79        result=$1
  80        shift
  81        expected=$1
  82        shift
  83        test_expect_$result "rebase $* of non-linear history is linearized upstream" "
  84                reset_rebase &&
  85                git rebase $* c w &&
  86                test_cmp_rev c HEAD~4 &&
  87                test_linear_range "\'"$expected"\'" c..
  88        "
  89}
  90#TODO: make order consistent across all flavors of rebase
  91test_run_rebase success 'd e n o' ''
  92test_run_rebase success 'd e n o' -m
  93test_run_rebase success 'd n o e' -i
  94
  95test_run_rebase () {
  96        result=$1
  97        shift
  98        expected=$1
  99        shift
 100        test_expect_$result "rebase $* of non-linear history with merges after upstream merge is linearized" "
 101                reset_rebase &&
 102                git rebase $* c v &&
 103                test_cmp_rev c HEAD~4 &&
 104                test_linear_range "\'"$expected"\'" c..
 105        "
 106}
 107#TODO: make order consistent across all flavors of rebase
 108test_run_rebase success 'd e n o' ''
 109test_run_rebase success 'd e n o' -m
 110test_run_rebase success 'd n o e' -i
 111
 112if ! test_have_prereq REBASE_P; then
 113        skip_all='skipping git rebase -p tests, as asked for'
 114        test_done
 115fi
 116
 117test_expect_success "rebase -p is no-op in non-linear history" "
 118        reset_rebase &&
 119        git rebase -p d w &&
 120        test_cmp_rev w HEAD
 121"
 122
 123test_expect_success "rebase -p is no-op when base inside second parent" "
 124        reset_rebase &&
 125        git rebase -p e w &&
 126        test_cmp_rev w HEAD
 127"
 128
 129test_expect_failure "rebase -p --root on non-linear history is a no-op" "
 130        reset_rebase &&
 131        git rebase -p --root w &&
 132        test_cmp_rev w HEAD
 133"
 134
 135test_expect_success "rebase -p re-creates merge from side branch" "
 136        reset_rebase &&
 137        git rebase -p z w &&
 138        test_cmp_rev z HEAD^ &&
 139        test_cmp_rev w^2 HEAD^2
 140"
 141
 142test_expect_success "rebase -p re-creates internal merge" "
 143        reset_rebase &&
 144        git rebase -p c w &&
 145        test_cmp_rev c HEAD~4 &&
 146        test_cmp_rev HEAD^2^ HEAD~3 &&
 147        test_revision_subjects 'd n e o w' HEAD~3 HEAD~2 HEAD^2 HEAD^ HEAD
 148"
 149
 150test_expect_success "rebase -p can re-create two branches on onto" "
 151        reset_rebase &&
 152        git rebase -p --onto c d w &&
 153        test_cmp_rev c HEAD~3 &&
 154        test_cmp_rev c HEAD^2^ &&
 155        test_revision_subjects 'n e o w' HEAD~2 HEAD^2 HEAD^ HEAD
 156"
 157
 158#       f
 159#      /
 160# a---b---c---g---h
 161#      \
 162#       d---gp--i
 163#        \       \
 164#         e-------u
 165#
 166# gp = cherry-picked g
 167# h = reverted g
 168test_expect_success 'setup of non-linear-history for patch-equivalence tests' '
 169        git checkout e &&
 170        test_merge u i
 171'
 172
 173test_expect_success "rebase -p re-creates history around dropped commit matching upstream" "
 174        reset_rebase &&
 175        git rebase -p h u &&
 176        test_cmp_rev h HEAD~3 &&
 177        test_cmp_rev HEAD^2^ HEAD~2 &&
 178        test_revision_subjects 'd i e u' HEAD~2 HEAD^2 HEAD^ HEAD
 179"
 180
 181test_expect_success "rebase -p --onto in merged history drops patches in upstream" "
 182        reset_rebase &&
 183        git rebase -p --onto f h u &&
 184        test_cmp_rev f HEAD~3 &&
 185        test_cmp_rev HEAD^2^ HEAD~2 &&
 186        test_revision_subjects 'd i e u' HEAD~2 HEAD^2 HEAD^ HEAD
 187"
 188
 189test_expect_success "rebase -p --onto in merged history does not drop patches in onto" "
 190        reset_rebase &&
 191        git rebase -p --onto h f u &&
 192        test_cmp_rev h HEAD~3 &&
 193        test_cmp_rev HEAD^2~2 HEAD~2 &&
 194        test_revision_subjects 'd gp i e u' HEAD~2 HEAD^2^ HEAD^2 HEAD^ HEAD
 195"
 196
 197# a---b---c---g---h
 198#      \
 199#       d---gp--s
 200#        \   \ /
 201#         \   X
 202#          \ / \
 203#           e---t
 204#
 205# gp = cherry-picked g
 206# h = reverted g
 207test_expect_success 'setup of non-linear-history for dropping whole side' '
 208        git checkout gp &&
 209        test_merge s e &&
 210        git checkout e &&
 211        test_merge t gp
 212'
 213
 214test_expect_failure "rebase -p drops merge commit when entire first-parent side is dropped" "
 215        reset_rebase &&
 216        git rebase -p h s &&
 217        test_cmp_rev h HEAD~2 &&
 218        test_linear_range 'd e' h..
 219"
 220
 221test_expect_success "rebase -p drops merge commit when entire second-parent side is dropped" "
 222        reset_rebase &&
 223        git rebase -p h t &&
 224        test_cmp_rev h HEAD~2 &&
 225        test_linear_range 'd e' h..
 226"
 227
 228# a---b---c
 229#      \
 230#       d---e
 231#        \   \
 232#         n---r
 233#          \
 234#           o
 235#
 236# r = tree-same with n
 237test_expect_success 'setup of non-linear-history for empty commits' '
 238        git checkout n &&
 239        git merge --no-commit e &&
 240        git reset n . &&
 241        git commit -m r &&
 242        git reset --hard &&
 243        git clean -f &&
 244        git tag r
 245'
 246
 247test_expect_success "rebase -p re-creates empty internal merge commit" "
 248        reset_rebase &&
 249        git rebase -p c r &&
 250        test_cmp_rev c HEAD~3 &&
 251        test_cmp_rev HEAD^2^ HEAD~2 &&
 252        test_revision_subjects 'd e n r' HEAD~2 HEAD^2 HEAD^ HEAD
 253"
 254
 255test_expect_success "rebase -p re-creates empty merge commit" "
 256        reset_rebase &&
 257        git rebase -p o r &&
 258        test_cmp_rev e HEAD^2 &&
 259        test_cmp_rev o HEAD^ &&
 260        test_revision_subjects 'r' HEAD
 261"
 262
 263test_done