Skip to content

Commit ff0e4a0

Browse files
committed
RFC: Push diffs in Git before telling GitHub about it
I ran into an issue reordering diffs in a direct stack (the one currently ending in pytorch/executorch#9586) where GitHub's API complained `There are no new commits between base branch 'gh/swolchok/395/head' and head branch 'gh/swolchok/383/head'`. This seems to have fixed it for me.
1 parent 1ca03bc commit ff0e4a0

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/ghstack/submit.py

+24-23
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,30 @@ def push_updates(
14791479
push_branches: List[str] = []
14801480
force_push_branches: List[str] = []
14811481

1482+
for s in reversed(diffs_to_submit):
1483+
# It is VERY important that we do base updates BEFORE real
1484+
# head updates, otherwise GitHub will spuriously think that
1485+
# the user pushed a number of patches as part of the PR,
1486+
# when actually they were just from the (new) upstream
1487+
# branch
1488+
1489+
for diff, b in s.push_branches:
1490+
if b == "orig":
1491+
q = force_push_branches
1492+
elif b == "base":
1493+
q = base_push_branches
1494+
else:
1495+
q = push_branches
1496+
q.append(push_spec(diff, branch(s.username, s.ghnum, b)))
1497+
# Careful! Don't push master.
1498+
# TODO: These pushes need to be atomic (somehow)
1499+
if base_push_branches:
1500+
self._git_push(base_push_branches)
1501+
if push_branches:
1502+
self._git_push(push_branches, force=self.force)
1503+
if force_push_branches:
1504+
self._git_push(force_push_branches, force=True)
1505+
14821506
for s in reversed(diffs_to_submit):
14831507
# NB: GraphQL API does not support modifying PRs
14841508
assert not s.closed
@@ -1516,29 +1540,6 @@ def push_updates(
15161540
body=stack_desc,
15171541
)
15181542

1519-
# It is VERY important that we do base updates BEFORE real
1520-
# head updates, otherwise GitHub will spuriously think that
1521-
# the user pushed a number of patches as part of the PR,
1522-
# when actually they were just from the (new) upstream
1523-
# branch
1524-
1525-
for diff, b in s.push_branches:
1526-
if b == "orig":
1527-
q = force_push_branches
1528-
elif b == "base":
1529-
q = base_push_branches
1530-
else:
1531-
q = push_branches
1532-
q.append(push_spec(diff, branch(s.username, s.ghnum, b)))
1533-
# Careful! Don't push master.
1534-
# TODO: These pushes need to be atomic (somehow)
1535-
if base_push_branches:
1536-
self._git_push(base_push_branches)
1537-
if push_branches:
1538-
self._git_push(push_branches)
1539-
if force_push_branches:
1540-
self._git_push(force_push_branches, force=True)
1541-
15421543
# Report what happened
15431544
def format_url(s: DiffMeta) -> str:
15441545
return "https://{github_url}/{owner}/{repo}/pull/{number}".format(

0 commit comments

Comments
 (0)