3 test_description='rebase topology tests with merges'
5 . "$TEST_DIRECTORY"/lib-rebase.sh
7 test_revision_subjects () {
10 set -- $(git log --format=%s --no-walk=unsorted "$@")
11 test "$expected" = "$*"
21 test_expect_success 'setup of non-linear-history' '
50 test_expect_$result "rebase $* after merge from upstream" "
53 test_cmp_rev e HEAD~2 &&
54 test_linear_range 'n o' e..
57 test_run_rebase success ''
58 test_run_rebase success -m
59 test_run_rebase success -i
66 test_expect_$result "rebase $* of non-linear history is linearized in place" "
69 test_cmp_rev d HEAD~3 &&
70 test_linear_range "\'"$expected"\'" d..
73 test_run_rebase success 'n o e' ''
74 test_run_rebase success 'n o e' -m
75 test_run_rebase success 'n o e' -i
82 test_expect_$result "rebase $* of non-linear history is linearized upstream" "
85 test_cmp_rev c HEAD~4 &&
86 test_linear_range "\'"$expected"\'" c..
89 test_run_rebase success 'd n o e' ''
90 test_run_rebase success 'd n o e' -m
91 test_run_rebase success 'd n o e' -i
98 test_expect_$result "rebase $* of non-linear history with merges after upstream merge is linearized" "
101 test_cmp_rev c HEAD~4 &&
102 test_linear_range "\'"$expected"\'" c..
105 test_run_rebase success 'd n o e' ''
106 test_run_rebase success 'd n o e' -m
107 test_run_rebase success 'd n o e' -i
109 if ! test_have_prereq REBASE_P; then
110 skip_all='skipping git rebase -p tests, as asked for'
114 test_expect_success "rebase -p is no-op in non-linear history" "
120 test_expect_success "rebase -p is no-op when base inside second parent" "
126 test_expect_failure "rebase -p --root on non-linear history is a no-op" "
128 git rebase -p --root w &&
132 test_expect_success "rebase -p re-creates merge from side branch" "
135 test_cmp_rev z HEAD^ &&
136 test_cmp_rev w^2 HEAD^2
139 test_expect_success "rebase -p re-creates internal merge" "
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
147 test_expect_success "rebase -p can re-create two branches on onto" "
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
163 # gp = cherry-picked g
165 test_expect_success 'setup of non-linear-history for patch-equivalence tests' '
170 test_expect_success "rebase -p re-creates history around dropped commit matching upstream" "
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
178 test_expect_success "rebase -p --onto in merged history drops patches in upstream" "
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
186 test_expect_success "rebase -p --onto in merged history does not drop patches in onto" "
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
202 # gp = cherry-picked g
204 test_expect_success 'setup of non-linear-history for dropping whole side' '
211 test_expect_failure "rebase -p drops merge commit when entire first-parent side is dropped" "
214 test_cmp_rev h HEAD~2 &&
215 test_linear_range 'd e' h..
218 test_expect_success "rebase -p drops merge commit when entire second-parent side is dropped" "
221 test_cmp_rev h HEAD~2 &&
222 test_linear_range 'd e' h..
233 # r = tree-same with n
234 test_expect_success 'setup of non-linear-history for empty commits' '
236 git merge --no-commit e &&
244 test_expect_success "rebase -p re-creates empty internal merge commit" "
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
252 test_expect_success "rebase -p re-creates empty merge commit" "
255 test_cmp_rev e HEAD^2 &&
256 test_cmp_rev o HEAD^ &&
257 test_revision_subjects 'r' HEAD