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" 9shift 10set --$(git log --format=%s --no-walk=unsorted "$@") 11test"$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 49shift 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 63shift 64 expected=$1 65shift 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} 73test_run_rebase success 'n o e''' 74test_run_rebase success 'n o e'-m 75test_run_rebase success 'n o e'-i 76 77test_run_rebase () { 78 result=$1 79shift 80 expected=$1 81shift 82 test_expect_$result"rebase $* of non-linear history is linearized upstream"" 83 reset_rebase && 84 git rebase $* c w && 85 test_cmp_rev c HEAD~4 && 86 test_linear_range "\'"$expected"\'" c.. 87 " 88} 89test_run_rebase success 'd n o e''' 90test_run_rebase success 'd n o e'-m 91test_run_rebase success 'd n o e'-i 92 93test_run_rebase () { 94 result=$1 95shift 96 expected=$1 97shift 98 test_expect_$result"rebase $* of non-linear history with merges after upstream merge is linearized"" 99 reset_rebase && 100 git rebase $* c v && 101 test_cmp_rev c HEAD~4 && 102 test_linear_range "\'"$expected"\'" c.. 103 " 104} 105test_run_rebase success 'd n o e''' 106test_run_rebase success 'd n o e'-m 107test_run_rebase success 'd n o e'-i 108 109if! test_have_prereq REBASE_P;then 110 skip_all='skipping git rebase -p tests, as asked for' 111 test_done 112fi 113 114test_expect_success "rebase -p is no-op in non-linear history"" 115 reset_rebase && 116 git rebase -p d w && 117 test_cmp_rev w HEAD 118" 119 120test_expect_success "rebase -p is no-op when base inside second parent"" 121 reset_rebase && 122 git rebase -p e w && 123 test_cmp_rev w HEAD 124" 125 126test_expect_failure "rebase -p --root on non-linear history is a no-op"" 127 reset_rebase && 128 git rebase -p --root w && 129 test_cmp_rev w HEAD 130" 131 132test_expect_success "rebase -p re-creates merge from side branch"" 133 reset_rebase && 134 git rebase -p z w && 135 test_cmp_rev z HEAD^ && 136 test_cmp_rev w^2 HEAD^2 137" 138 139test_expect_success "rebase -p re-creates internal merge"" 140 reset_rebase && 141 git rebase -p c w && 142 test_cmp_rev c HEAD~4 && 143 test_cmp_rev HEAD^2^ HEAD~3 && 144 test_revision_subjects 'd n e o w' HEAD~3 HEAD~2 HEAD^2 HEAD^ HEAD 145" 146 147test_expect_success "rebase -p can re-create two branches on onto"" 148 reset_rebase && 149 git rebase -p --onto c d w && 150 test_cmp_rev c HEAD~3 && 151 test_cmp_rev c HEAD^2^ && 152 test_revision_subjects 'n e o w' HEAD~2 HEAD^2 HEAD^ HEAD 153" 154 155# f 156# / 157# a---b---c---g---h 158# \ 159# d---gp--i 160# \ \ 161# e-------u 162# 163# gp = cherry-picked g 164# h = reverted g 165test_expect_success 'setup of non-linear-history for patch-equivalence tests'' 166 git checkout e && 167 test_merge u i 168' 169 170test_expect_success "rebase -p re-creates history around dropped commit matching upstream"" 171 reset_rebase && 172 git rebase -p h u && 173 test_cmp_rev h HEAD~3 && 174 test_cmp_rev HEAD^2^ HEAD~2 && 175 test_revision_subjects 'd i e u' HEAD~2 HEAD^2 HEAD^ HEAD 176" 177 178test_expect_success "rebase -p --onto in merged history drops patches in upstream"" 179 reset_rebase && 180 git rebase -p --onto f h u && 181 test_cmp_rev f HEAD~3 && 182 test_cmp_rev HEAD^2^ HEAD~2 && 183 test_revision_subjects 'd i e u' HEAD~2 HEAD^2 HEAD^ HEAD 184" 185 186test_expect_success "rebase -p --onto in merged history does not drop patches in onto"" 187 reset_rebase && 188 git rebase -p --onto h f u && 189 test_cmp_rev h HEAD~3 && 190 test_cmp_rev HEAD^2~2 HEAD~2 && 191 test_revision_subjects 'd gp i e u' HEAD~2 HEAD^2^ HEAD^2 HEAD^ HEAD 192" 193 194# a---b---c---g---h 195# \ 196# d---gp--s 197# \ \ / 198# \ X 199# \ / \ 200# e---t 201# 202# gp = cherry-picked g 203# h = reverted g 204test_expect_success 'setup of non-linear-history for dropping whole side'' 205 git checkout gp && 206 test_merge s e && 207 git checkout e && 208 test_merge t gp 209' 210 211test_expect_failure "rebase -p drops merge commit when entire first-parent side is dropped"" 212 reset_rebase && 213 git rebase -p h s && 214 test_cmp_rev h HEAD~2 && 215 test_linear_range 'd e' h.. 216" 217 218test_expect_success "rebase -p drops merge commit when entire second-parent side is dropped"" 219 reset_rebase && 220 git rebase -p h t && 221 test_cmp_rev h HEAD~2 && 222 test_linear_range 'd e' h.. 223" 224 225# a---b---c 226# \ 227# d---e 228# \ \ 229# n---r 230# \ 231# o 232# 233# r = tree-same with n 234test_expect_success 'setup of non-linear-history for empty commits'' 235 git checkout n && 236 git merge --no-commit e && 237 git reset n . && 238 git commit -m r && 239 git reset --hard && 240 git clean -f && 241 git tag r 242' 243 244test_expect_success "rebase -p re-creates empty internal merge commit"" 245 reset_rebase && 246 git rebase -p c r && 247 test_cmp_rev c HEAD~3 && 248 test_cmp_rev HEAD^2^ HEAD~2 && 249 test_revision_subjects 'd e n r' HEAD~2 HEAD^2 HEAD^ HEAD 250" 251 252test_expect_success "rebase -p re-creates empty merge commit"" 253 reset_rebase && 254 git rebase -p o r && 255 test_cmp_rev e HEAD^2 && 256 test_cmp_rev o HEAD^ && 257 test_revision_subjects 'r' HEAD 258" 259 260test_done