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
14 jumps over the lazy dog."
15 for i in 1 2 3 4 5 6 7 8 9 10
20 test_expect_success setup '
22 git commit -m"initial" &&
24 echo "11 $T" >>original &&
25 git commit -a -m"main updates a bit." &&
27 echo "12 $T" >>original &&
28 git commit -a -m"main updates a bit more." &&
31 (echo "0 $T" && cat original) >renamed &&
33 git update-index --force-remove original &&
34 git commit -a -m"side renames and edits." &&
36 tr "[a-z]" "[A-Z]" <original >newfile &&
38 git commit -a -m"side edits further." &&
39 git branch second-side &&
41 tr "[a-m]" "[A-M]" <original >newfile &&
43 git commit -a -m"side edits once again." &&
45 git branch test-rebase side &&
46 git branch test-rebase-pick side &&
47 git branch test-reference-pick side &&
48 git branch test-conflicts side &&
49 git checkout -b test-merge side
52 test_expect_success 'reference merge' '
53 git merge -s recursive -m "reference merge" main
56 PRE_REBASE=$(git rev-parse test-rebase)
57 test_expect_success rebase '
58 git checkout test-rebase &&
59 GIT_TRACE=1 git rebase --merge main
62 test_expect_success 'test-rebase@{1} is pre rebase' '
63 test $PRE_REBASE = $(git rev-parse test-rebase@{1})
66 test_expect_success 'merge and rebase should match' '
67 git diff-tree -r test-rebase test-merge >difference &&
77 test_expect_success 'rebase the other way' '
78 git reset --hard main &&
79 git rebase --merge side
82 test_expect_success 'rebase -Xtheirs' '
83 git checkout -b conflicting main~2 &&
84 echo "AB $T" >> original &&
85 git commit -mconflicting original &&
86 git rebase -Xtheirs main &&
91 test_expect_success 'rebase -Xtheirs from orphan' '
92 git checkout --orphan orphan-conflicting main~2 &&
93 echo "AB $T" >> original &&
94 git commit -morphan-conflicting original &&
95 git rebase -Xtheirs main &&
100 test_expect_success 'merge and rebase should match' '
101 git diff-tree -r test-rebase test-merge >difference &&
102 if test -s difference
111 test_expect_success 'picking rebase' '
112 git reset --hard side &&
113 git rebase --merge --onto main side^^ &&
114 mb=$(git merge-base main HEAD) &&
115 if test "$mb" = "$(git rev-parse main)"
122 f=$(git diff-tree --name-only HEAD^ HEAD) &&
123 g=$(git diff-tree --name-only HEAD^^ HEAD^) &&
134 test_expect_success 'rebase -s funny -Xopt' '
135 test_when_finished "rm -fr test-bin funny.was.run" &&
137 cat >test-bin/git-merge-funny <<-EOF &&
139 case "\$1" in --opt) ;; *) exit 2 ;; esac
142 exec git merge-recursive "\$@"
144 chmod +x test-bin/git-merge-funny &&
146 git checkout -b test-funny main^ &&
149 PATH=./test-bin:$PATH &&
150 git rebase -s funny -Xopt main
152 test -f funny.was.run
155 test_expect_success 'rebase --skip works with two conflicts in a row' '
156 git checkout second-side &&
157 tr "[A-Z]" "[a-z]" <newfile >tmp &&
159 git commit -a -m"edit conflicting with side" &&
160 tr "[d-f]" "[D-F]" <newfile >tmp &&
162 git commit -a -m"another edit conflicting with side" &&
163 test_must_fail git rebase --merge test-conflicts &&
164 test_must_fail git rebase --skip &&
168 test_expect_success '--reapply-cherry-picks' '
171 # O(1-10) -- O(1-11) -- O(0-10) main
173 # -- O(1-11) -- O(1-12) otherbranch
175 printf "Line %d\n" $(test_seq 1 10) >repo/file.txt &&
176 git -C repo add file.txt &&
177 git -C repo commit -m "base commit" &&
179 printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
180 git -C repo commit -a -m "add 11" &&
182 printf "Line %d\n" $(test_seq 0 10) >repo/file.txt &&
183 git -C repo commit -a -m "add 0 delete 11" &&
185 git -C repo checkout -b otherbranch HEAD^^ &&
186 printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
187 git -C repo commit -a -m "add 11 in another branch" &&
189 printf "Line %d\n" $(test_seq 1 12) >repo/file.txt &&
190 git -C repo commit -a -m "add 12 in another branch" &&
192 # Regular rebase fails, because the 1-11 commit is deduplicated
193 test_must_fail git -C repo rebase --merge main 2> err &&
194 test_i18ngrep "error: could not apply.*add 12 in another branch" err &&
195 git -C repo rebase --abort &&
197 # With --reapply-cherry-picks, it works
198 git -C repo rebase --merge --reapply-cherry-picks main
201 test_expect_success '--reapply-cherry-picks refrains from reading unneeded blobs' '
204 # O(1-10) -- O(1-11) -- O(1-12) main
206 # -- O(0-10) otherbranch
208 printf "Line %d\n" $(test_seq 1 10) >server/file.txt &&
209 git -C server add file.txt &&
210 git -C server commit -m "merge base" &&
212 printf "Line %d\n" $(test_seq 1 11) >server/file.txt &&
213 git -C server commit -a -m "add 11" &&
215 printf "Line %d\n" $(test_seq 1 12) >server/file.txt &&
216 git -C server commit -a -m "add 12" &&
218 git -C server checkout -b otherbranch HEAD^^ &&
219 printf "Line %d\n" $(test_seq 0 10) >server/file.txt &&
220 git -C server commit -a -m "add 0" &&
222 test_config -C server uploadpack.allowfilter 1 &&
223 test_config -C server uploadpack.allowanysha1inwant 1 &&
225 git clone --filter=blob:none "file://$(pwd)/server" client &&
226 git -C client checkout origin/main &&
227 git -C client checkout origin/otherbranch &&
229 # Sanity check to ensure that the blobs from the merge base and "add
231 git -C client rev-list --objects --all --missing=print >missing_list &&
232 MERGE_BASE_BLOB=$(git -C server rev-parse main^^:file.txt) &&
233 ADD_11_BLOB=$(git -C server rev-parse main^:file.txt) &&
234 grep "[?]$MERGE_BASE_BLOB" missing_list &&
235 grep "[?]$ADD_11_BLOB" missing_list &&
237 git -C client rebase --merge --reapply-cherry-picks origin/main &&
239 # The blob from the merge base had to be fetched, but not "add 11"
240 git -C client rev-list --objects --all --missing=print >missing_list &&
241 ! grep "[?]$MERGE_BASE_BLOB" missing_list &&
242 grep "[?]$ADD_11_BLOB" missing_list