[GHF] Add support for new style stacks (#116873)

Where base stack targets default branch, rather than base. But as
default branch is likely to advance, since PR was made, search for
mergebase before determining whether `base`..`head` are in sync with `orig` branch
Also, rather than hardcode default branch name, fetch it from `GitHubPR.default_branch()`

Test Plan: https://github.com/malfet/deleteme/pull/77

Pull Request resolved: https://github.com/pytorch/pytorch/pull/116873
Approved by: https://github.com/ezyang
This commit is contained in:
Nikita Shulga
2024-01-05 20:32:24 +00:00
committed by PyTorch MergeBot
parent 71d8fe690f
commit 0f0020d76f
2 changed files with 25 additions and 5 deletions

View File

@ -674,10 +674,15 @@ def get_ghstack_prs(
for stacked_pr, rev in entire_stack:
if stacked_pr.is_closed():
continue
if not are_ghstack_branches_in_sync(repo, stacked_pr.head_ref()):
base_ref = stacked_pr.base_ref()
if base_ref == pr.default_branch():
base_ref = repo.get_merge_base(
f"{repo.remote}/{base_ref}", f"{repo.remote}/{stacked_pr.head_ref()}"
)
if not are_ghstack_branches_in_sync(repo, stacked_pr.head_ref(), base_ref):
raise RuntimeError(
f"PR {stacked_pr.pr_num} is out of sync with the corresponding revision {rev} on "
+ f"branch {orig_ref} that would be merged into main. "
+ f"branch {stacked_pr.get_ghstack_orig_ref()} that would be merged into {stacked_pr.default_branch()}. "
+ "This usually happens because there is a non ghstack change in the PR. "
+ f"Please sync them and try again (ex. make the changes on {orig_ref} and run ghstack)."
)