Skip to content

Commit c22861c

Browse files
authored
Updated land.py to do merging after push was successful (#292)
1 parent 1e7f2ce commit c22861c

13 files changed

+45
-48
lines changed

src/ghstack/diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
RAW_PULL_REQUEST_RESOLVED = (
17-
r"(Pull Request resolved|Pull-Request-resolved): "
17+
r"(Pull Request resolved|Pull-Request-resolved|Pull-Request): "
1818
r"https://{github_url}/(?P<owner>[^/]+)/(?P<repo>[^/]+)/pull/(?P<number>[0-9]+)"
1919
)
2020

@@ -93,7 +93,7 @@ class Diff:
9393
# be the same.
9494
source_id: str
9595

96-
# The contents of 'Pull-Request-resolved'. This is None for
96+
# The contents of 'Pull-Request'. This is None for
9797
# diffs that haven't been submitted by ghstack. For BC reasons,
9898
# this also accepts gh-metadata.
9999
pull_request_resolved: Optional[PullRequestResolved]

src/ghstack/land.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,18 @@ def main(
152152
sh.git("cherry-pick", "--abort")
153153
raise
154154

155+
# All good! Push!
156+
maybe_force_arg = []
157+
if needs_force:
158+
maybe_force_arg = ["--force-with-lease"]
159+
sh.git(
160+
"push", *maybe_force_arg, remote_name, f"HEAD:refs/heads/{default_branch}"
161+
)
162+
155163
# Advance base to head to "close" the PR for all PRs.
156-
# This has to happen before the push because the push
157-
# will trigger a closure, but we want a *merge*. This should
158-
# happen after the cherry-pick, because the cherry-picks can
159-
# fail
164+
# This happens after the cherry-pick and push, because the cherry-picks
165+
# can fail (merge conflict) and the push can also fail (race condition)
166+
160167
# TODO: It might be helpful to advance orig to reflect the true
161168
# state of upstream at the time we are doing the land, and then
162169
# directly *merge* head into base, so that the PR accurately
@@ -173,14 +180,6 @@ def main(
173180
)
174181
github.notify_merged(pr_resolved)
175182

176-
# All good! Push!
177-
maybe_force_arg = []
178-
if needs_force:
179-
maybe_force_arg = ["--force-with-lease"]
180-
sh.git(
181-
"push", *maybe_force_arg, remote_name, f"HEAD:refs/heads/{default_branch}"
182-
)
183-
184183
# Delete the branches
185184
for orig_ref, _ in stack_orig_refs:
186185
# TODO: regex here so janky

src/ghstack/submit.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ def elaborate_diff(
810810
convert a pre-existing PR in the old style to the new format which
811811
supports bidirectional syncing. If you would like to blow away the old
812812
PR and start anew, edit the Summary in the Phabricator diff to delete
813-
the line 'Pull-Request-resolved' and then run ghexport again.
813+
the line 'Pull-Request' and then run ghexport again.
814814
"""
815815
)
816816

@@ -827,7 +827,7 @@ def elaborate_diff(
827827
to export your diff.
828828
829829
If you think this is in error, edit the Summary in the Phabricator diff
830-
to delete the line 'Pull-Request-resolved' and then run ghexport again.
830+
to delete the line 'Pull-Request' and then run ghexport again.
831831
"""
832832
)
833833
else:
@@ -964,9 +964,7 @@ def process_commit(
964964
if self.direct:
965965
trailers_to_add.append(f"ghstack-comment-id: {elab_diff.comment_id}")
966966

967-
trailers_to_add.append(
968-
f"Pull-Request-resolved: {pull_request_resolved.url()}"
969-
)
967+
trailers_to_add.append(f"Pull-Request: {pull_request_resolved.url()}")
970968

971969
commit_msg = ghstack.trailers.interpret_trailers(
972970
strip_mentions(diff.summary.rstrip()), trailers_to_add
@@ -1773,7 +1771,7 @@ def _default_title_and_body(
17731771
commit_body = RE_GHSTACK_SOURCE_ID.sub("", commit_body)
17741772
# Comment ID is not necessary; source of truth is orig commit
17751773
commit_body = RE_GHSTACK_COMMENT_ID.sub("", commit_body)
1776-
# Don't store Pull request resolved in the PR body; it's
1774+
# Don't store Pull request in the PR body; it's
17771775
# unnecessary
17781776
commit_body = ghstack.diff.re_pull_request_resolved_w_sp(self.github_url).sub(
17791777
"", commit_body

test/land/default_branch_change.py.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ assert_expected_inline(
4848
assert_expected_inline(
4949
get_upstream_sh().git("log", "--oneline", "main"),
5050
"""\
51-
19fa5fa Commit A
51+
8927014 Commit A
5252
dc8bfe4 Initial commit""",
5353
)
5454

@@ -82,15 +82,15 @@ assert_github_state(
8282

8383
This is commit B
8484

85-
* f5135dc Initial 2
85+
* ab7d5ca Initial 2
8686

8787
Repository state:
8888

89-
* f5135dc (gh/ezyang/2/head)
89+
* ab7d5ca (gh/ezyang/2/head)
9090
| Initial 2
91-
* 61e5c2a (gh/ezyang/2/base)
91+
* 742ae0b (gh/ezyang/2/base)
9292
| Initial 2 (base update)
93-
* 19fa5fa (main, gh/ezyang/1/orig)
93+
* 8927014 (main, gh/ezyang/1/orig)
9494
| Commit A
9595
| * 36fcfdf (gh/ezyang/1/head)
9696
| | Initial 1
@@ -107,13 +107,13 @@ gh_land(diff2.pr_url)
107107
assert_expected_inline(
108108
get_upstream_sh().git("log", "--oneline", "master"),
109109
"""\
110-
19e7996 Commit B
111-
cb4e674 Commit A
110+
d779d84 Commit B
111+
542f79d Commit A
112112
dc8bfe4 Initial commit""",
113113
)
114114
assert_expected_inline(
115115
get_upstream_sh().git("log", "--oneline", "main"),
116116
"""\
117-
19fa5fa Commit A
117+
8927014 Commit A
118118
dc8bfe4 Initial commit""",
119119
)

test/land/ff.py.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ gh_land(pr_url)
1111
assert_expected_inline(
1212
get_upstream_sh().git("log", "--oneline", "master"),
1313
"""\
14-
19fa5fa Commit A
14+
8927014 Commit A
1515
dc8bfe4 Initial commit""",
1616
)
1717

test/land/ff_stack.py.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ gh_land(pr_url)
1616
assert_expected_inline(
1717
get_upstream_sh().git("log", "--oneline", "master"),
1818
"""\
19-
3c9c5eb Commit B
20-
6eb4d4f Commit A
19+
b6c40ad Commit B
20+
851cf96 Commit A
2121
dc8bfe4 Initial commit""",
2222
)

test/land/ff_stack_two_phase.py.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ gh_land(pr_url2)
1818
assert_expected_inline(
1919
get_upstream_sh().git("log", "--oneline", "master"),
2020
"""\
21-
3c9c5eb Commit B
22-
6eb4d4f Commit A
21+
b6c40ad Commit B
22+
851cf96 Commit A
2323
dc8bfe4 Initial commit""",
2424
)

test/land/invalid_resubmit.py.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ else:
4444

4545
This is commit A
4646

47-
* c461f2f New PR
47+
* 98fcb03 New PR
4848

4949
Repository state:
5050

51-
* c461f2f (gh/ezyang/1/head)
51+
* 98fcb03 (gh/ezyang/1/head)
5252
| New PR
53-
* 58e6f57 (gh/ezyang/1/base)
53+
* 0d09e7d (gh/ezyang/1/base)
5454
| New PR (base update)
55-
* 19fa5fa (HEAD -> master)
55+
* 8927014 (HEAD -> master)
5656
| Commit A
5757
* dc8bfe4
5858
Initial commit

test/land/non_ff.py.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ gh_land(pr_url)
1717
assert_expected_inline(
1818
get_upstream_sh().git("log", "--oneline", "master"),
1919
"""\
20-
1d53e04 Commit A
20+
d43d06e Commit A
2121
38808c0 Commit U
2222
dc8bfe4 Initial commit""",
2323
)

test/land/non_ff_stack_two_phase.py.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ gh_land(pr_url2)
2222
assert_expected_inline(
2323
get_upstream_sh().git("log", "--oneline", "master"),
2424
"""\
25-
613567d Commit B
26-
4dfc330 Commit A
25+
ec1d0de Commit B
26+
d8a6272 Commit A
2727
a8ca27f Commit C
2828
dc8bfe4 Initial commit""",
2929
)

0 commit comments

Comments
 (0)