@@ -325,27 +325,35 @@ class Scheduler {
325325 await cancelPreSubmitTargets (pullRequest: pullRequest, reason: reason);
326326
327327 final slug = pullRequest.base ! .repo! .slug ();
328+ final isFusion = slug == Config .flutterSlug;
328329
329330 // The MQ only waits for "required status checks" before deciding whether to
330331 // merge the PR into the target branch. This required check added to both
331332 // the PR and to the merge group, and so it must be completed in both cases.
332- final lock = await lockMergeGroupChecks (slug, pullRequest.head! .sha! );
333+ final CheckRun ? lock;
334+ {
335+ final prBranch = pullRequest.head! .ref;
336+ if (isFusion && Config .defaultBranch (slug) == prBranch) {
337+ lock = await _lockMergeGroupChecks (slug, pullRequest.head! .sha! );
338+ } else {
339+ lock = null ;
340+ log.debug ('Skipping merge queue guard: $slug /$prBranch ' );
341+ }
342+ }
333343
334- // Track if we should unlock the merge group lock in case of non-fusion or
335- // revert bots.
344+ // Track if we should unlock the merge group lock in case of rever bots.
345+ // This is different than simply not having a lock - because flutter/flutter
346+ // master requires to see the lock existing and have been passed (versus
347+ // non-existence).
336348 var unlockMergeGroup = false ;
337349
338350 final ciValidationCheckRun = await _createCiYamlCheckRun (pullRequest, slug);
339351
340352 log.info ('Creating presubmit targets for ${pullRequest .number }' );
341353 Object ? exception;
342- final isFusion = slug == Config .flutterSlug;
343354 do {
344355 try {
345356 final sha = pullRequest.head! .sha! ;
346- if (! isFusion) {
347- unlockMergeGroup = true ;
348- }
349357
350358 // Both the author and label should be checked to make sure that no one is
351359 // attempting to get a pull request without check through.
@@ -381,7 +389,7 @@ class Scheduler {
381389
382390 await _runCiTestingStage (
383391 pullRequest: pullRequest,
384- checkRunGuard: '$ lock ' ,
392+ checkRunGuard: lock? . toString () ?? ' ' ,
385393 logCrumb: logCrumb,
386394
387395 // The if-branch already skips the engine build phase.
@@ -470,8 +478,8 @@ class Scheduler {
470478 // Normally the lock stays pending until the PR is ready to be enqueued, but
471479 // there are situations (see code above) when it needs to be unlocked
472480 // immediately.
473- if (unlockMergeGroup) {
474- await unlockMergeQueueGuard (slug, pullRequest.head! .sha! , lock);
481+ if (lock != null && unlockMergeGroup) {
482+ await _unlockMergeQueueGuard (slug, pullRequest.head! .sha! , lock);
475483 }
476484 log.info (
477485 'Finished triggering builds for: pr ${pullRequest .number }, commit ${pullRequest .base !.sha }, branch ${pullRequest .head !.ref } and slug $slug }' ,
@@ -561,12 +569,12 @@ class Scheduler {
561569 }
562570 log.info ('$logCrumb : scheduling merge group checks' );
563571
564- final lock = await lockMergeGroupChecks (slug, headSha);
572+ final lock = await _lockMergeGroupChecks (slug, headSha);
565573
566574 // If the repo is not fusion, it doesn't run anything in the MQ, so just
567575 // close the merge group guard.
568576 if (! isFusion) {
569- await unlockMergeQueueGuard (slug, headSha, lock);
577+ await _unlockMergeQueueGuard (slug, headSha, lock);
570578 return ;
571579 }
572580
730738 /// While this check is still in progress, the merge queue will not merge the
731739 /// respective PR onto the target branch (e.g. main or master), because this
732740 /// check is "required".
733- Future <CheckRun > lockMergeGroupChecks (
741+ Future <CheckRun > _lockMergeGroupChecks (
734742 RepositorySlug slug,
735743 String headSha,
736744 ) async {
754762 ///
755763 /// If the guard is guarding a pull request, this immediately makes the pull
756764 /// request eligible for enqueuing into the merge queue.
757- Future <void > unlockMergeQueueGuard (
765+ Future <void > _unlockMergeQueueGuard (
758766 RepositorySlug slug,
759767 String headSha,
760768 CheckRun lock,
@@ -1113,7 +1121,11 @@ $s
11131121 required String logCrumb,
11141122 }) async {
11151123 log.info ('$logCrumb : Stage completed: ${CiStage .fusionTests }' );
1116- await unlockMergeQueueGuard (slug, sha, checkRunFromString (mergeQueueGuard));
1124+ await _unlockMergeQueueGuard (
1125+ slug,
1126+ sha,
1127+ checkRunFromString (mergeQueueGuard),
1128+ );
11171129 }
11181130
11191131 /// Returns the presubmit targets for the fusion repo [pullRequest] that should run for the given [stage] .
11461158
11471159 // Unlock the guarding check_run.
11481160 final checkRunGuard = checkRunFromString (mergeQueueGuard);
1149- await unlockMergeQueueGuard (slug, sha, checkRunGuard);
1161+ await _unlockMergeQueueGuard (slug, sha, checkRunGuard);
11501162 }
11511163
11521164 /// Schedules post-engine build tests (i.e. engine tests, and framework tests).
0 commit comments