Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/ghstack/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,9 @@ async def run(self) -> List[DiffMeta]:
# we always have to generate orig commits for submitted diffs.)
# However, commits_to_submit does not necessarily contain
# diffs_to_rebase. If you ask to submit only a prefix of your current
# stack, the suffix is not to be submitted, but it needs to be rebased
# (to, e.g., update the ghstack-source-id)
# stack, the suffix is not to be submitted, but it needs to be rebased.
# Existing ghstack PRs in the suffix still need their source IDs kept
# up-to-date, but local-only suffix commits should stay local-only.

commit_count = len(commits_to_submit)

Expand Down Expand Up @@ -883,7 +884,8 @@ async def prepare_updates(
pr_info_cache = await self._prefetch_pr_info(commits_to_rebase)

# Phase 1: Process all commits (oldest first) to determine what
# needs updating, create head/base commits, and identify new PRs.
# needs updating, create head/base commits, and identify submitted
# new PRs.
# New PRs are NOT pushed/created yet — deferred to batch operation.
submit_set = set(h.commit_id for h in commits_to_submit)
diff_meta_index: Dict[GitCommitHash, DiffMeta] = {}
Expand Down Expand Up @@ -1214,6 +1216,12 @@ async def process_commit(
)
return None

# This commit has no existing PR and is not part of the requested
# submit set. It may still be rebased later if an earlier commit was
# rewritten, but it should not get ghstack trailers or a new PR.
if elab_diff is None and not submit:
return None

# Edge case: check if the commit is empty; if so skip submitting
if base.tree == diff.tree:
self._warn_empty(diff, elab_diff)
Expand Down
26 changes: 26 additions & 0 deletions test/submit/prefix_only_new_suffix_no_metadata.py.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from ghstack.test_prelude import *

await init_test()

await commit("A")
await commit("B")
await commit("C")

# Submit only A. B and C are local-only suffix commits and should not be
# annotated as ghstack PRs.
(A,) = await gh_submit("Submit bottom only", revs=["HEAD~2"], stack=False)

bottom_msg = await git("show", "-s", "--pretty=%B", "HEAD~2")
middle_msg = await git("show", "-s", "--pretty=%B", "HEAD~")
top_msg = await git("show", "-s", "--pretty=%B", "HEAD")

assert "ghstack-source-id:" in bottom_msg
assert "Pull-Request:" in bottom_msg

assert "ghstack-source-id:" not in middle_msg, middle_msg
assert "Pull-Request:" not in middle_msg, middle_msg

assert "ghstack-source-id:" not in top_msg, top_msg
assert "Pull-Request:" not in top_msg, top_msg

ok()
Loading