git-gc.txt: fix typo about gc.writeCommitGraph
[git/raj.git] / t / t3425-rebase-topology-merges.sh
blob5f892e33d7e53e8871df256b3344ebd0476712ee
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 ''
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 #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
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..
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
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..
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
112 if ! test_have_prereq REBASE_P; then
113 skip_all='skipping git rebase -p tests, as asked for'
114 test_done
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
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
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
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
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
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
160 # a---b---c---g---h
162 # d---gp--i
163 # \ \
164 # e-------u
166 # gp = cherry-picked g
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
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
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
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 &&
194 test_revision_subjects 'd gp i e u' HEAD~2 HEAD^2^ HEAD^2 HEAD^ HEAD
197 # a---b---c---g---h
199 # d---gp--s
200 # \ \ /
201 # \ X
202 # \ / \
203 # e---t
205 # gp = cherry-picked g
206 # h = reverted g
207 test_expect_success 'setup of non-linear-history for dropping whole side' '
208 git checkout gp &&
209 test_merge s e &&
210 git checkout e &&
211 test_merge t gp
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..
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..
228 # a---b---c
230 # d---e
231 # \ \
232 # n---r
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
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
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
263 test_done