3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='git rebase --merge test'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
15 jumps over the lazy dog."
16 for i
in 1 2 3 4 5 6 7 8 9 10
21 test_expect_success setup
'
23 git commit -m"initial" &&
25 echo "11 $T" >>original &&
26 git commit -a -m"main updates a bit." &&
28 echo "12 $T" >>original &&
29 git commit -a -m"main updates a bit more." &&
32 (echo "0 $T" && cat original) >renamed &&
34 git update-index --force-remove original &&
35 git commit -a -m"side renames and edits." &&
37 tr "[a-z]" "[A-Z]" <original >newfile &&
39 git commit -a -m"side edits further." &&
40 git branch second-side &&
42 tr "[a-m]" "[A-M]" <original >newfile &&
44 git commit -a -m"side edits once again." &&
46 git branch test-rebase side &&
47 git branch test-rebase-pick side &&
48 git branch test-reference-pick side &&
49 git branch test-conflicts side &&
50 git checkout -b test-merge side
53 test_expect_success
'reference merge' '
54 git merge -s recursive -m "reference merge" main
57 PRE_REBASE
=$
(git rev-parse test-rebase
)
58 test_expect_success rebase
'
59 git checkout test-rebase &&
60 GIT_TRACE=1 git rebase --merge main
63 test_expect_success
'test-rebase@{1} is pre rebase' '
64 test $PRE_REBASE = $(git rev-parse test-rebase@{1})
67 test_expect_success
'merge and rebase should match' '
68 git diff-tree -r test-rebase test-merge >difference &&
78 test_expect_success
'rebase the other way' '
79 git reset --hard main &&
80 git rebase --merge side
83 test_expect_success
'rebase -Xtheirs' '
84 git checkout -b conflicting main~2 &&
85 echo "AB $T" >> original &&
86 git commit -mconflicting original &&
87 git rebase -Xtheirs main &&
92 test_expect_success
'rebase -Xtheirs from orphan' '
93 git checkout --orphan orphan-conflicting main~2 &&
94 echo "AB $T" >> original &&
95 git commit -morphan-conflicting original &&
96 git rebase -Xtheirs main &&
101 test_expect_success
'merge and rebase should match' '
102 git diff-tree -r test-rebase test-merge >difference &&
103 if test -s difference
112 test_expect_success
'picking rebase' '
113 git reset --hard side &&
114 git rebase --merge --onto main side^^ &&
115 mb=$(git merge-base main HEAD) &&
116 if test "$mb" = "$(git rev-parse main)"
123 f=$(git diff-tree --name-only HEAD^ HEAD) &&
124 g=$(git diff-tree --name-only HEAD^^ HEAD^) &&
135 test_expect_success
'rebase --skip works with two conflicts in a row' '
136 git checkout second-side &&
137 tr "[A-Z]" "[a-z]" <newfile >tmp &&
139 git commit -a -m"edit conflicting with side" &&
140 tr "[d-f]" "[D-F]" <newfile >tmp &&
142 git commit -a -m"another edit conflicting with side" &&
143 test_must_fail git rebase --merge test-conflicts &&
144 test_must_fail git rebase --skip &&
148 test_expect_success
'--reapply-cherry-picks' '
151 # O(1-10) -- O(1-11) -- O(0-10) main
153 # -- O(1-11) -- O(1-12) otherbranch
155 printf "Line %d\n" $(test_seq 1 10) >repo/file.txt &&
156 git -C repo add file.txt &&
157 git -C repo commit -m "base commit" &&
159 printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
160 git -C repo commit -a -m "add 11" &&
162 printf "Line %d\n" $(test_seq 0 10) >repo/file.txt &&
163 git -C repo commit -a -m "add 0 delete 11" &&
165 git -C repo checkout -b otherbranch HEAD^^ &&
166 printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
167 git -C repo commit -a -m "add 11 in another branch" &&
169 printf "Line %d\n" $(test_seq 1 12) >repo/file.txt &&
170 git -C repo commit -a -m "add 12 in another branch" &&
172 # Regular rebase fails, because the 1-11 commit is deduplicated
173 test_must_fail git -C repo rebase --merge main 2> err &&
174 test_i18ngrep "error: could not apply.*add 12 in another branch" err &&
175 git -C repo rebase --abort &&
177 # With --reapply-cherry-picks, it works
178 git -C repo rebase --merge --reapply-cherry-picks main
181 test_expect_success
'--reapply-cherry-picks refrains from reading unneeded blobs' '
184 # O(1-10) -- O(1-11) -- O(1-12) main
186 # -- O(0-10) otherbranch
188 printf "Line %d\n" $(test_seq 1 10) >server/file.txt &&
189 git -C server add file.txt &&
190 git -C server commit -m "merge base" &&
192 printf "Line %d\n" $(test_seq 1 11) >server/file.txt &&
193 git -C server commit -a -m "add 11" &&
195 printf "Line %d\n" $(test_seq 1 12) >server/file.txt &&
196 git -C server commit -a -m "add 12" &&
198 git -C server checkout -b otherbranch HEAD^^ &&
199 printf "Line %d\n" $(test_seq 0 10) >server/file.txt &&
200 git -C server commit -a -m "add 0" &&
202 test_config -C server uploadpack.allowfilter 1 &&
203 test_config -C server uploadpack.allowanysha1inwant 1 &&
205 git clone --filter=blob:none "file://$(pwd)/server" client &&
206 git -C client checkout origin/main &&
207 git -C client checkout origin/otherbranch &&
209 # Sanity check to ensure that the blobs from the merge base and "add
211 git -C client rev-list --objects --all --missing=print >missing_list &&
212 MERGE_BASE_BLOB=$(git -C server rev-parse main^^:file.txt) &&
213 ADD_11_BLOB=$(git -C server rev-parse main^:file.txt) &&
214 grep "[?]$MERGE_BASE_BLOB" missing_list &&
215 grep "[?]$ADD_11_BLOB" missing_list &&
217 git -C client rebase --merge --reapply-cherry-picks origin/main &&
219 # The blob from the merge base had to be fetched, but not "add 11"
220 git -C client rev-list --objects --all --missing=print >missing_list &&
221 ! grep "[?]$MERGE_BASE_BLOB" missing_list &&
222 grep "[?]$ADD_11_BLOB" missing_list