Skip to content

Commit dae5933

Browse files
merge master onto branches before checks
1 parent dd69fbb commit dae5933

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

check_dependent_project.sh

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,47 @@ process_pr_description_line() {
208208
done
209209
companions+=("$repo")
210210

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"
213221
pushd "$companions_dir/$repo" >/dev/null
222+
223+
# Clone the companion's branch
214224
local ref="$(curl \
215225
-sSL \
216226
-H "Authorization: token $github_api_token" \
217227
"$github_api/repos/$org/$repo/pulls/$pr_number" | \
218228
jq -e -r ".head.ref"
219229
)"
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"
221231
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+
222252
popd >/dev/null
223253

224254
# collect also the companions of companions
@@ -301,6 +331,20 @@ main() {
301331
git config --global user.email '<>'
302332
git config --global pull.rebase false
303333

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+
304348
discover_our_crates
305349

306350
# process_pr_description calls itself for each companion in the description on
@@ -310,6 +354,7 @@ main() {
310354

311355
local dependent_repo_dir="$companions_dir/$dependent_repo"
312356
if ! [ -e "$dependent_repo_dir" ]; then
357+
echo "Cloning $dependent_repo directly as it was not detected as a companion"
313358
dependent_repo_dir="$this_repo_dir/$dependent_repo"
314359
git clone --depth=1 "https://github.com/$org/$dependent_repo.git" "$dependent_repo_dir"
315360
fi

0 commit comments

Comments
 (0)