162
git rebase --skip
163
'
164
165
+test_expect_success '--reapply-cherry-picks' '
166
+ git init repo &&
167
+
168
+ # O(1-10) -- O(1-11) -- O(0-10) master
169
+ # \
170
+ # -- O(1-11) -- O(1-12) otherbranch
171
+
172
+ printf "Line %d\n" $(test_seq 1 10) >repo/file.txt &&
173
+ git -C repo add file.txt &&
174
+ git -C repo commit -m "base commit" &&
175
+
176
+ printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
177
+ git -C repo commit -a -m "add 11" &&
178
+
179
+ printf "Line %d\n" $(test_seq 0 10) >repo/file.txt &&
180
+ git -C repo commit -a -m "add 0 delete 11" &&
181
+
182
+ git -C repo checkout -b otherbranch HEAD^^ &&
183
+ printf "Line %d\n" $(test_seq 1 11) >repo/file.txt &&
184
+ git -C repo commit -a -m "add 11 in another branch" &&
185
+
186
+ printf "Line %d\n" $(test_seq 1 12) >repo/file.txt &&
187
+ git -C repo commit -a -m "add 12 in another branch" &&
188
+
189
+ # Regular rebase fails, because the 1-11 commit is deduplicated
190
+ test_must_fail git -C repo rebase --merge master 2> err &&
191
+ test_i18ngrep "error: could not apply.*add 12 in another branch" err &&
192
+ git -C repo rebase --abort &&
193
+
194
+ # With --reapply-cherry-picks, it works
195
+ git -C repo rebase --merge --reapply-cherry-picks master
196
+'
197
+
198
+test_expect_success '--reapply-cherry-picks refrains from reading unneeded blobs' '
199
+ git init server &&
200
+
201
+ # O(1-10) -- O(1-11) -- O(1-12) master
202
+ # \
203
+ # -- O(0-10) otherbranch
204
+
205
+ printf "Line %d\n" $(test_seq 1 10) >server/file.txt &&
206
+ git -C server add file.txt &&
207
+ git -C server commit -m "merge base" &&
208
+
209
+ printf "Line %d\n" $(test_seq 1 11) >server/file.txt &&
210
+ git -C server commit -a -m "add 11" &&
211
+
212
+ printf "Line %d\n" $(test_seq 1 12) >server/file.txt &&
213
+ git -C server commit -a -m "add 12" &&
214
+
215
+ git -C server checkout -b otherbranch HEAD^^ &&
216
+ printf "Line %d\n" $(test_seq 0 10) >server/file.txt &&
217
+ git -C server commit -a -m "add 0" &&
218
+
219
+ test_config -C server uploadpack.allowfilter 1 &&
220
+ test_config -C server uploadpack.allowanysha1inwant 1 &&
221
+
222
+ git clone --filter=blob:none "file://$(pwd)/server" client &&
223
+ git -C client checkout origin/master &&
224
+ git -C client checkout origin/otherbranch &&
225
+
226
+ # Sanity check to ensure that the blobs from the merge base and "add
227
+ # 11" are missing
228
+ git -C client rev-list --objects --all --missing=print >missing_list &&
229
+ MERGE_BASE_BLOB=$(git -C server rev-parse master^^:file.txt) &&
230
+ ADD_11_BLOB=$(git -C server rev-parse master^:file.txt) &&
231
+ grep "[?]$MERGE_BASE_BLOB" missing_list &&
232
+ grep "[?]$ADD_11_BLOB" missing_list &&
233
+
234
+ git -C client rebase --merge --reapply-cherry-picks origin/master &&
235
+
236
+ # The blob from the merge base had to be fetched, but not "add 11"
237
+ git -C client rev-list --objects --all --missing=print >missing_list &&
238
+ ! grep "[?]$MERGE_BASE_BLOB" missing_list &&
239
+ grep "[?]$ADD_11_BLOB" missing_list
240
+'
241
+
242
test_done