CodingGuidelines: do not ==/!= compare with 0 or '\0' or NULL
[git.git] / t / t3425-rebase-topology-merges.sh
blobe42faa44e74f1abe247aa1c16da9d5582123d42c
1 #!/bin/sh
3 test_description='rebase topology tests with merges'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-rebase.sh
7 test_revision_subjects () {
8 expected="$1"
9 shift
10 set -- $(git log --format=%s --no-walk=unsorted "$@")
11 test "$expected" = "$*"
14 # a---b-----------c
15 # \ \
16 # d-------e \
17 # \ \ \
18 # n---o---w---v
19 # \
20 # z
21 test_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 &&
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 &&
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
47 test_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..
57 test_run_rebase success --apply
58 test_run_rebase success -m
59 test_run_rebase success -i
61 test_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..
73 test_run_rebase success 'n o e' --apply
74 test_run_rebase success 'n o e' -m
75 test_run_rebase success 'n o e' -i
77 test_run_rebase () {
78 result=$1
79 shift
80 expected=$1
81 shift
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..
89 test_run_rebase success 'd n o e' --apply
90 test_run_rebase success 'd n o e' -m
91 test_run_rebase success 'd n o e' -i
93 test_run_rebase () {
94 result=$1
95 shift
96 expected=$1
97 shift
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..
105 test_run_rebase success 'd n o e' --apply
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'
111 test_done
114 test_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
120 test_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
126 test_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
132 test_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
139 test_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
147 test_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
157 # a---b---c---g---h
159 # d---gp--i
160 # \ \
161 # e-------u
163 # gp = cherry-picked g
164 # h = reverted g
165 test_expect_success 'setup of non-linear-history for patch-equivalence tests' '
166 git checkout e &&
167 test_merge u i
170 test_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
178 test_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
186 test_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
194 # a---b---c---g---h
196 # d---gp--s
197 # \ \ /
198 # \ X
199 # \ / \
200 # e---t
202 # gp = cherry-picked g
203 # h = reverted g
204 test_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
211 test_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..
218 test_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..
225 # a---b---c
227 # d---e
228 # \ \
229 # n---r
233 # r = tree-same with n
234 test_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
244 test_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
252 test_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
260 test_done