]>
Commit | Line | Data |
---|---|---|
3f213981 MZ |
1 | #!/bin/sh |
2 | ||
3 | test_description='rebase topology tests with merges' | |
4 | . ./test-lib.sh | |
5 | . "$TEST_DIRECTORY"/lib-rebase.sh | |
6 | ||
7 | test_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 | |
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 && | |
99094a7a | 27 | test_commit e && |
3f213981 MZ |
28 | |
29 | git checkout c && | |
30 | test_commit g && | |
31 | revert h g && | |
32 | git checkout d && | |
984f78d2 | 33 | cherry_pick gp g && |
3f213981 MZ |
34 | test_commit i && |
35 | git checkout b && | |
99094a7a | 36 | test_commit f && |
3f213981 MZ |
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 | ||
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.. | |
55 | " | |
56 | } | |
57 | test_run_rebase success '' | |
58 | test_run_rebase success -m | |
59 | test_run_rebase success -i | |
60 | ||
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.. | |
71 | " | |
72 | } | |
73 | #TODO: make order consistent across all flavors of rebase | |
74 | test_run_rebase success 'e n o' '' | |
75 | test_run_rebase success 'e n o' -m | |
76 | test_run_rebase success 'n o e' -i | |
77 | ||
78 | test_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 | |
91 | test_run_rebase success 'd e n o' '' | |
92 | test_run_rebase success 'd e n o' -m | |
93 | test_run_rebase success 'd n o e' -i | |
94 | ||
95 | test_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 | |
108 | test_run_rebase success 'd e n o' '' | |
109 | test_run_rebase success 'd e n o' -m | |
110 | test_run_rebase success 'd n o e' -i | |
111 | ||
11aad464 JS |
112 | if ! test_have_prereq REBASE_P; then |
113 | skip_all='skipping git rebase -p tests, as asked for' | |
114 | test_done | |
115 | fi | |
116 | ||
3f213981 MZ |
117 | test_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 | ||
123 | test_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 | ||
129 | test_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 | ||
135 | test_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 | ||
142 | test_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 | ||
150 | test_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 | # \ | |
984f78d2 | 162 | # d---gp--i |
3f213981 MZ |
163 | # \ \ |
164 | # e-------u | |
165 | # | |
984f78d2 | 166 | # gp = cherry-picked g |
3f213981 MZ |
167 | # h = reverted g |
168 | test_expect_success 'setup of non-linear-history for patch-equivalence tests' ' | |
169 | git checkout e && | |
170 | test_merge u i | |
171 | ' | |
172 | ||
173 | test_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 | ||
181 | test_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 | ||
189 | test_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 && | |
984f78d2 | 194 | test_revision_subjects 'd gp i e u' HEAD~2 HEAD^2^ HEAD^2 HEAD^ HEAD |
3f213981 MZ |
195 | " |
196 | ||
197 | # a---b---c---g---h | |
198 | # \ | |
984f78d2 | 199 | # d---gp--s |
3f213981 MZ |
200 | # \ \ / |
201 | # \ X | |
202 | # \ / \ | |
203 | # e---t | |
204 | # | |
984f78d2 | 205 | # gp = cherry-picked g |
3f213981 MZ |
206 | # h = reverted g |
207 | test_expect_success 'setup of non-linear-history for dropping whole side' ' | |
984f78d2 | 208 | git checkout gp && |
3f213981 MZ |
209 | test_merge s e && |
210 | git checkout e && | |
984f78d2 | 211 | test_merge t gp |
3f213981 MZ |
212 | ' |
213 | ||
214 | test_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 | ||
221 | test_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 | |
237 | test_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 | ||
247 | test_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 | ||
255 | test_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 | ||
263 | test_done |