Skip to content

Conversation

@vmoens
Copy link
Collaborator

@vmoens vmoens commented Jan 14, 2026

This PR modifies ghstack land to append the PR number to commit messages, matching GitHub's native merge behavior.

Changes

land.py:

  • After cherry-picking each commit, amend the message to add (#<PR_NUMBER>) to the subject line
  • Only add if not already present
  • Preserve author/committer dates for consistency

submit.py:

  • Handle closed PRs whose branches were deleted (common after landing)
  • When processing closed PRs, check if the commit exists on master by comparing tree hashes
  • If found with same tree hash, skip (already landed); if modified or not found, raise appropriate error
  • Skip closed PRs in check_invariants validation

Example

Before:

abc123 Fix critical bug

After landing PR #456:

def789 Fix critical bug (#456)

Testing

All 10 existing land tests pass. Tests were updated to expect PR numbers in commit messages using EXPECTTEST_ACCEPT=1.

Closes #313

Copy link
Collaborator Author

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_land fails: Can't find deleted branch, crashes
  • invalid_resubmit fails: Doesn't detect modified closed PRs, allows invalid resubmits
  • update_after_land fails: Same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PR number to commit messages when landing, like GitHub does

1 participant