Skip to content

Commit 4d73bf1

Browse files
committed
Add PR number during PR creation instead of land
1 parent 3987ada commit 4d73bf1

16 files changed

+53
-72
lines changed

src/ghstack/land.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -145,41 +145,13 @@ def main(
145145
stack_orig_refs.append((ref, pr_resolved))
146146

147147
# OK, actually do the land now
148-
for orig_ref, pr_resolved in stack_orig_refs:
148+
for orig_ref, _ in stack_orig_refs:
149149
try:
150150
sh.git("cherry-pick", f"{remote_name}/{orig_ref}")
151151
except BaseException:
152152
sh.git("cherry-pick", "--abort")
153153
raise
154154

155-
# Add PR number to commit message like GitHub does
156-
commit_msg = sh.git("log", "-1", "--pretty=%B")
157-
# Get the original author and committer dates to preserve the commit hash
158-
author_date = sh.git("log", "-1", "--pretty=%aD")
159-
committer_date = sh.git("log", "-1", "--pretty=%cD")
160-
lines = commit_msg.split("\n")
161-
if lines:
162-
# Add PR number to the subject line (first line)
163-
subject = lines[0].rstrip()
164-
# Only add if not already present
165-
pr_tag = f"(#{pr_resolved.number})"
166-
if pr_tag not in subject:
167-
subject = f"{subject} {pr_tag}"
168-
lines[0] = subject
169-
new_msg = "\n".join(lines)
170-
# Preserve dates to keep the commit hash consistent
171-
sh.git(
172-
"commit",
173-
"--amend",
174-
"-F",
175-
"-",
176-
input=new_msg,
177-
env={
178-
"GIT_AUTHOR_DATE": author_date,
179-
"GIT_COMMITTER_DATE": committer_date,
180-
},
181-
)
182-
183155
# All good! Push!
184156
maybe_force_arg = []
185157
if needs_force:

src/ghstack/submit.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,9 +1017,18 @@ def process_commit(
10171017

10181018
trailers_to_add.append(f"Pull-Request: {pull_request_resolved.url()}")
10191019

1020-
commit_msg = ghstack.trailers.interpret_trailers(
1021-
strip_mentions(diff.summary.rstrip()), trailers_to_add
1022-
)
1020+
# Add PR number to the commit subject line, like GitHub does
1021+
summary = strip_mentions(diff.summary.rstrip())
1022+
lines = summary.split("\n")
1023+
if lines:
1024+
subject = lines[0].rstrip()
1025+
pr_tag = f"(#{elab_diff.number})"
1026+
if pr_tag not in subject:
1027+
subject = f"{subject} {pr_tag}"
1028+
lines[0] = subject
1029+
summary = "\n".join(lines)
1030+
1031+
commit_msg = ghstack.trailers.interpret_trailers(summary, trailers_to_add)
10231032

10241033
return DiffMeta(
10251034
elab_diff=elab_diff,

test/land/default_branch_change.py.test

Lines changed: 9 additions & 9 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-
8927014 Commit A
51+
47df7ee Commit A (#500)
5252
dc8bfe4 Initial commit""",
5353
)
5454

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

8383
This is commit B
8484

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

8787
Repository state:
8888

89-
* ab7d5ca (gh/ezyang/2/head)
89+
* d8c62d3 (gh/ezyang/2/head)
9090
| Initial 2
91-
* 742ae0b (gh/ezyang/2/base)
91+
* 66b4cd5 (gh/ezyang/2/base)
9292
| Initial 2 (base update)
93-
* 8927014 (main, gh/ezyang/1/orig)
94-
| Commit A
93+
* 47df7ee (main, gh/ezyang/1/orig)
94+
| Commit A (#500)
9595
| * 36fcfdf (gh/ezyang/1/head)
9696
| | Initial 1
9797
| * 5a32949 (gh/ezyang/1/base)
@@ -107,13 +107,13 @@ gh_land(diff2.pr_url)
107107
assert_expected_inline(
108108
get_upstream_sh().git("log", "--oneline", "master"),
109109
"""\
110-
6b7e56e Commit B (#501)
111-
1132c50 Commit A (#500)
110+
c9d09d0 Commit B (#501)
111+
fd22a9f Commit A (#500)
112112
dc8bfe4 Initial commit""",
113113
)
114114
assert_expected_inline(
115115
get_upstream_sh().git("log", "--oneline", "main"),
116116
"""\
117-
8927014 Commit A
117+
47df7ee Commit A (#500)
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-
d518c9f Commit A (#500)
14+
47df7ee Commit A (#500)
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-
4099517 Commit B (#501)
20-
c28edd5 Commit A (#500)
19+
87b6210 Commit B (#501)
20+
9704af8 Commit A (#500)
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-
4099517 Commit B (#501)
22-
c28edd5 Commit A (#500)
21+
87b6210 Commit B (#501)
22+
9704af8 Commit A (#500)
2323
dc8bfe4 Initial commit""",
2424
)

test/land/invalid_resubmit.py.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ else:
3737

3838
(omitted)
3939

40-
[O] #501 Commit A (gh/ezyang/1/head -> gh/ezyang/1/base)
40+
[O] #501 Commit A (#500) (gh/ezyang/1/head -> gh/ezyang/1/base)
4141

4242
Stack:
4343
* __->__ #501
4444

4545
This is commit A
4646

47-
* d1c3c7e New PR
47+
* 5f15948 New PR
4848

4949
Repository state:
5050

51-
* d1c3c7e (gh/ezyang/1/head)
51+
* 5f15948 (gh/ezyang/1/head)
5252
| New PR
53-
* 5f392f5 (gh/ezyang/1/base)
53+
* e54a43e (gh/ezyang/1/base)
5454
| New PR (base update)
55-
* d518c9f (HEAD -> master)
55+
* 47df7ee (HEAD -> master)
5656
| Commit A (#500)
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-
8b61aeb Commit A (#500)
20+
16b6f13 Commit A (#500)
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-
402e96c Commit B (#501)
26-
e388a10 Commit A (#500)
25+
964e411 Commit B (#501)
26+
e291f44 Commit A (#500)
2727
a8ca27f Commit C
2828
dc8bfe4 Initial commit""",
2929
)

test/land/update_after_land.py.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ else:
5555

5656
This is commit B
5757

58-
* 87c9ccd Run 3
58+
* ba208a5 Run 3
5959
* 16e1e12 Initial 1
6060

6161
Repository state:
6262

63-
* 87c9ccd (gh/ezyang/2/head)
63+
* ba208a5 (gh/ezyang/2/head)
6464
|\\ Run 3
65-
| * a800ca6 (gh/ezyang/2/base)
65+
| * 0d1bf0c (gh/ezyang/2/base)
6666
| |\\ Run 3 (base update)
67-
| | * 70eb094 (HEAD -> master)
67+
| | * ae7fbca (HEAD -> master)
6868
| | | Commit A (#500)
6969
| | * 7f0288c
7070
| | | Commit U

0 commit comments

Comments
 (0)