@@ -208,17 +208,47 @@ process_pr_description_line() {
208
208
done
209
209
companions+= (" $repo " )
210
210
211
- # clone the companion and use it to patch dependencies in the future
212
- git clone --depth= 1 " https://github.com/$org /$repo .git" " $companions_dir /$repo "
211
+ # Heuristic: assume the companion PR has a common merge ancestor with master
212
+ # in its last N commits.
213
+ local merge_ancestor_max_depth= 100
214
+
215
+ # Clone the default branch of this companion's target repository (assumed to
216
+ # be named "master")
217
+ git clone \
218
+ --depth= $merge_ancestor_max_depth \
219
+ " https://github.com/$org /$repo .git" \
220
+ " $companions_dir /$repo "
213
221
pushd " $companions_dir /$repo " > /dev/null
222
+
223
+ # Clone the companion's branch
214
224
local ref= " $( curl \
215
225
-sSL \
216
226
-H " Authorization: token $github_api_token " \
217
227
" $github_api /repos/$org /$repo /pulls/$pr_number " | \
218
228
jq -e -r " .head.ref"
219
229
) "
220
- git fetch --depth= 1 origin " pull/$pr_number /head:$ref "
230
+ git fetch --depth= $merge_ancestor_max_depth origin " pull/$pr_number /head:$ref "
221
231
git checkout " $ref "
232
+
233
+ echo "
234
+ Attempting to merge $repo #$pr_number with master after fetching its last $merge_ancestor_max_depth commits.
235
+
236
+ If this step fails, either:
237
+
238
+ - $repo #$pr_number has conflicts with master
239
+
240
+ *OR*
241
+
242
+ - A common merge ancestor could not be found between master and the last $merge_ancestor_max_depth commits of $repo #$pr_number .
243
+
244
+ Both cases can be solved by merging master into $repo #$pr_number .
245
+ "
246
+ git show-ref origin/master
247
+ git merge origin/master \
248
+ --verbose \
249
+ --no-edit \
250
+ -m " Merge master of $repo into companion $repo #$pr_number "
251
+
222
252
popd > /dev/null
223
253
224
254
# collect also the companions of companions
@@ -301,6 +331,20 @@ main() {
301
331
git config --global user.email ' <>'
302
332
git config --global pull.rebase false
303
333
334
+ # Merge master into this branch so that we have a better expectation of the
335
+ # integration still working after this PR lands.
336
+ # Since master is being merged here, at the start the dependency chain, we'll
337
+ # have to do the same on all discovered companions since they also might have
338
+ # accompanying changes for the code being brought in.
339
+ local branch=" $( git symbolic-ref --short HEAD) "
340
+ git fetch --force origin master
341
+ git show-ref origin/master
342
+ echo " Merge master into $branch "
343
+ git merge origin/master \
344
+ --verbose \
345
+ --no-edit \
346
+ -m " Merge master into $branch "
347
+
304
348
discover_our_crates
305
349
306
350
# process_pr_description calls itself for each companion in the description on
@@ -310,6 +354,7 @@ main() {
310
354
311
355
local dependent_repo_dir=" $companions_dir /$dependent_repo "
312
356
if ! [ -e " $dependent_repo_dir " ]; then
357
+ echo " Cloning $dependent_repo directly as it was not detected as a companion"
313
358
dependent_repo_dir=" $this_repo_dir /$dependent_repo "
314
359
git clone --depth=1 " https://github.com/$org /$dependent_repo .git" " $dependent_repo_dir "
315
360
fi
0 commit comments