-
Notifications
You must be signed in to change notification settings - Fork 79
Add PR number to commit messages during land #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -487,18 +487,20 @@ def run(self) -> List[DiffMeta]: | |
| d = ghstack.git.convert_header(h, self.github_url) | ||
| if d.pull_request_resolved is not None: | ||
| ed = self.elaborate_diff(d) | ||
| pre_branch_state_index[h.commit_id] = PreBranchState( | ||
| head_commit_id=GitCommitHash( | ||
| self.sh.git( | ||
| "rev-parse", f"{self.remote_name}/{ed.head_ref}" | ||
| ) | ||
| ), | ||
| base_commit_id=GitCommitHash( | ||
| self.sh.git( | ||
| "rev-parse", f"{self.remote_name}/{ed.base_ref}" | ||
| ) | ||
| ), | ||
| ) | ||
| # Skip closed PRs (e.g., after landing) where branches have been deleted | ||
| if not ed.closed: | ||
| pre_branch_state_index[h.commit_id] = PreBranchState( | ||
| head_commit_id=GitCommitHash( | ||
| self.sh.git( | ||
| "rev-parse", f"{self.remote_name}/{ed.head_ref}" | ||
| ) | ||
| ), | ||
| base_commit_id=GitCommitHash( | ||
| self.sh.git( | ||
| "rev-parse", f"{self.remote_name}/{ed.base_ref}" | ||
| ) | ||
| ), | ||
| ) | ||
|
|
||
| # NB: deduplicates | ||
| commit_index = { | ||
|
|
@@ -870,21 +872,24 @@ def elaborate_diff( | |
| "--header", | ||
| self.remote_name + "/" + branch_orig(username, gh_number), | ||
| ) | ||
| except RuntimeError as e: | ||
| except RuntimeError: | ||
| if r["closed"]: | ||
| raise RuntimeError( | ||
| f"Cannot ghstack a stack with closed PR #{number} whose branch was deleted. " | ||
| "If you were just trying to update a later PR in the stack, `git rebase` and try again. " | ||
| "Otherwise, you may have been trying to update a PR that was already closed. " | ||
| "To disassociate your update from the old PR and open a new PR, " | ||
| "run `ghstack unlink`, `git rebase` and then try again." | ||
| ) from e | ||
| raise | ||
| remote_summary = ghstack.git.split_header(rev_list)[0] | ||
| m_remote_source_id = RE_GHSTACK_SOURCE_ID.search(remote_summary.commit_msg) | ||
| remote_source_id = m_remote_source_id.group(1) if m_remote_source_id else None | ||
| m_comment_id = RE_GHSTACK_COMMENT_ID.search(remote_summary.commit_msg) | ||
| comment_id = int(m_comment_id.group(1)) if m_comment_id else None | ||
| # If the PR is closed and the branch is deleted (e.g., after landing), | ||
| # we can't get the remote source ID. Return None for it, which will | ||
| # signal to process_commit that this commit has been landed and should | ||
| # be skipped (not updated). | ||
| remote_source_id = None | ||
| comment_id = None | ||
| else: | ||
| raise | ||
| else: | ||
| remote_summary = ghstack.git.split_header(rev_list)[0] | ||
| m_remote_source_id = RE_GHSTACK_SOURCE_ID.search(remote_summary.commit_msg) | ||
| remote_source_id = ( | ||
| m_remote_source_id.group(1) if m_remote_source_id else None | ||
| ) | ||
| m_comment_id = RE_GHSTACK_COMMENT_ID.search(remote_summary.commit_msg) | ||
| comment_id = int(m_comment_id.group(1)) if m_comment_id else None | ||
|
|
||
| return DiffWithGitHubMetadata( | ||
| diff=diff, | ||
|
|
@@ -917,6 +922,48 @@ def process_commit( | |
| if elab_diff is not None and elab_diff.closed: | ||
| if self.direct: | ||
| self._raise_needs_rebase() | ||
| # If we're trying to submit a closed commit, check if it has been modified | ||
| if elab_diff.remote_source_id is None: | ||
| # The branch was deleted (e.g., after landing). Check if the commit has been | ||
| # modified by comparing source_ids. If the commit is reachable from master with | ||
| # the same source_id (tree hash), it means it was landed and we should skip it. | ||
| # Otherwise, it's been modified and we should raise an error. | ||
| try: | ||
| # Check if there's a commit on master with the same tree (source_id) | ||
| master_commits = self.sh.git( | ||
| "log", | ||
| "--format=%H %T", | ||
| f"{self.remote_name}/{self.base}", | ||
| "-n", | ||
| "100", # Check last 100 commits | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit suspect |
||
| ) | ||
| for line in master_commits.split("\n"): | ||
| if not line.strip(): | ||
| continue | ||
| commit_hash, tree_hash = line.split() | ||
| if tree_hash == diff.source_id: | ||
| # Found a commit on master with the same tree, so this commit | ||
| # was landed (just with a different commit message/hash) | ||
| return None | ||
| except Exception: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gives me the jeebies |
||
| pass | ||
| # Didn't find a matching commit on master, so this is a modified closed commit | ||
| raise RuntimeError( | ||
| f"Cannot ghstack a stack with closed PR #{elab_diff.number} whose branch was deleted. " | ||
| "If you were just trying to update a later PR in the stack, `git rebase` and try again. " | ||
| "Otherwise, you may have been trying to update a PR that was already closed. " | ||
| "To disassociate your update from the old PR and open a new PR, " | ||
| "run `ghstack unlink`, `git rebase` and then try again." | ||
| ) | ||
| elif diff.source_id != elab_diff.remote_source_id: | ||
| # The commit has been modified locally | ||
| raise RuntimeError( | ||
| f"Cannot ghstack a stack with closed PR #{elab_diff.number} whose branch was deleted. " | ||
| "If you were just trying to update a later PR in the stack, `git rebase` and try again. " | ||
| "Otherwise, you may have been trying to update a PR that was already closed. " | ||
| "To disassociate your update from the old PR and open a new PR, " | ||
| "run `ghstack unlink`, `git rebase` and then try again." | ||
| ) | ||
| return None | ||
|
|
||
| # Edge case: check if the commit is empty; if so skip submitting | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we amend commit messages in land.py to add PR numbers, we change the commit hash.
This creates an issue when users later try to submit new commits that are based on the old (pre-landing) commit.
Without these changes:
reuse_branch_refuse_landfails: Can't find deleted branch, crashesinvalid_resubmitfails: Doesn't detect modified closed PRs, allows invalid resubmitsupdate_after_landfails: Same issueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the changes I must review most carefully