t / t3425-rebase-topology-merges.shon commit Merge branch 'jc/plug-fmt-merge-msg-leak' (789e98d)
   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
 112test_expect_success "rebase -p is no-op in non-linear history" "
 113        reset_rebase &&
 114        git rebase -p d w &&
 115        test_cmp_rev w HEAD
 116"
 117
 118test_expect_success "rebase -p is no-op when base inside second parent" "
 119        reset_rebase &&
 120        git rebase -p e w &&
 121        test_cmp_rev w HEAD
 122"
 123
 124test_expect_failure "rebase -p --root on non-linear history is a no-op" "
 125        reset_rebase &&
 126        git rebase -p --root w &&
 127        test_cmp_rev w HEAD
 128"
 129
 130test_expect_success "rebase -p re-creates merge from side branch" "
 131        reset_rebase &&
 132        git rebase -p z w &&
 133        test_cmp_rev z HEAD^ &&
 134        test_cmp_rev w^2 HEAD^2
 135"
 136
 137test_expect_success "rebase -p re-creates internal merge" "
 138        reset_rebase &&
 139        git rebase -p c w &&
 140        test_cmp_rev c HEAD~4 &&
 141        test_cmp_rev HEAD^2^ HEAD~3 &&
 142        test_revision_subjects 'd n e o w' HEAD~3 HEAD~2 HEAD^2 HEAD^ HEAD
 143"
 144
 145test_expect_success "rebase -p can re-create two branches on onto" "
 146        reset_rebase &&
 147        git rebase -p --onto c d w &&
 148        test_cmp_rev c HEAD~3 &&
 149        test_cmp_rev c HEAD^2^ &&
 150        test_revision_subjects 'n e o w' HEAD~2 HEAD^2 HEAD^ HEAD
 151"
 152
 153#       f
 154#      /
 155# a---b---c---g---h
 156#      \
 157#       d---gp--i
 158#        \       \
 159#         e-------u
 160#
 161# gp = cherry-picked g
 162# h = reverted g
 163test_expect_success 'setup of non-linear-history for patch-equivalence tests' '
 164        git checkout e &&
 165        test_merge u i
 166'
 167
 168test_expect_success "rebase -p re-creates history around dropped commit matching upstream" "
 169        reset_rebase &&
 170        git rebase -p h u &&
 171        test_cmp_rev h HEAD~3 &&
 172        test_cmp_rev HEAD^2^ HEAD~2 &&
 173        test_revision_subjects 'd i e u' HEAD~2 HEAD^2 HEAD^ HEAD
 174"
 175
 176test_expect_success "rebase -p --onto in merged history drops patches in upstream" "
 177        reset_rebase &&
 178        git rebase -p --onto f h u &&
 179        test_cmp_rev f HEAD~3 &&
 180        test_cmp_rev HEAD^2^ HEAD~2 &&
 181        test_revision_subjects 'd i e u' HEAD~2 HEAD^2 HEAD^ HEAD
 182"
 183
 184test_expect_success "rebase -p --onto in merged history does not drop patches in onto" "
 185        reset_rebase &&
 186        git rebase -p --onto h f u &&
 187        test_cmp_rev h HEAD~3 &&
 188        test_cmp_rev HEAD^2~2 HEAD~2 &&
 189        test_revision_subjects 'd gp i e u' HEAD~2 HEAD^2^ HEAD^2 HEAD^ HEAD
 190"
 191
 192# a---b---c---g---h
 193#      \
 194#       d---gp--s
 195#        \   \ /
 196#         \   X
 197#          \ / \
 198#           e---t
 199#
 200# gp = cherry-picked g
 201# h = reverted g
 202test_expect_success 'setup of non-linear-history for dropping whole side' '
 203        git checkout gp &&
 204        test_merge s e &&
 205        git checkout e &&
 206        test_merge t gp
 207'
 208
 209test_expect_failure "rebase -p drops merge commit when entire first-parent side is dropped" "
 210        reset_rebase &&
 211        git rebase -p h s &&
 212        test_cmp_rev h HEAD~2 &&
 213        test_linear_range 'd e' h..
 214"
 215
 216test_expect_success "rebase -p drops merge commit when entire second-parent side is dropped" "
 217        reset_rebase &&
 218        git rebase -p h t &&
 219        test_cmp_rev h HEAD~2 &&
 220        test_linear_range 'd e' h..
 221"
 222
 223# a---b---c
 224#      \
 225#       d---e
 226#        \   \
 227#         n---r
 228#          \
 229#           o
 230#
 231# r = tree-same with n
 232test_expect_success 'setup of non-linear-history for empty commits' '
 233        git checkout n &&
 234        git merge --no-commit e &&
 235        git reset n . &&
 236        git commit -m r &&
 237        git reset --hard &&
 238        git clean -f &&
 239        git tag r
 240'
 241
 242test_expect_success "rebase -p re-creates empty internal merge commit" "
 243        reset_rebase &&
 244        git rebase -p c r &&
 245        test_cmp_rev c HEAD~3 &&
 246        test_cmp_rev HEAD^2^ HEAD~2 &&
 247        test_revision_subjects 'd e n r' HEAD~2 HEAD^2 HEAD^ HEAD
 248"
 249
 250test_expect_success "rebase -p re-creates empty merge commit" "
 251        reset_rebase &&
 252        git rebase -p o r &&
 253        test_cmp_rev e HEAD^2 &&
 254        test_cmp_rev o HEAD^ &&
 255        test_revision_subjects 'r' HEAD
 256"
 257
 258test_done