Skip to content

Commit 2e54b1f

Browse files
committed
Make --no-skip work again
Signed-off-by: Edward Yang <[email protected]> ghstack-source-id: f0150de ghstack-comment-id: 3356766633 Pull-Request: #302
1 parent 3af7e37 commit 2e54b1f

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

src/ghstack/submit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ def _create_non_orig_branches(
13741374
push_branches.head.commit is None
13751375
or updated_base
13761376
or push_branches.head.commit.tree != diff.tree
1377+
or self.no_skip
13771378
):
13781379
new_head = GitCommitHash(
13791380
self.sh.git(

src/ghstack/test_prelude.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,11 @@ def gh_submit(
189189
update_fields: bool = False,
190190
short: bool = False,
191191
no_skip: bool = False,
192+
force: bool = False,
192193
base: Optional[str] = None,
193194
revs: Sequence[str] = (),
194195
stack: bool = True,
196+
check_invariants: bool = True,
195197
) -> List[ghstack.submit.DiffMeta]:
196198
self = CTX
197199
r = ghstack.submit.main(
@@ -204,16 +206,18 @@ def gh_submit(
204206
repo_owner_opt="pytorch",
205207
repo_name_opt="pytorch",
206208
short=short,
209+
force=force,
207210
direct_opt=self.direct,
208211
no_skip=no_skip,
209212
github_url="github.com",
210213
remote_name="origin",
211214
base_opt=base,
212215
revs=revs,
213216
stack=stack,
214-
check_invariants=True,
217+
check_invariants=check_invariants,
215218
)
216-
self.check_global_github_invariants(self.direct)
219+
if check_invariants:
220+
self.check_global_github_invariants(self.direct)
217221
return r
218222

219223

test/submit/amend_message_only.py.test

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ if is_direct():
1616

1717
This is commit AAA
1818

19+
* 1774f4b Update A
1920
* 5cd944b Initial 1
2021

2122
Repository state:
2223

23-
* 5cd944b (gh/ezyang/1/next, gh/ezyang/1/head)
24+
* 1774f4b (gh/ezyang/1/next, gh/ezyang/1/head)
25+
| Update A
26+
* 5cd944b
2427
| Initial 1
2528
* dc8bfe4 (HEAD -> master)
2629
Initial commit
@@ -36,11 +39,14 @@ else:
3639

3740
This is commit AAA
3841

42+
* fa3f7db Update A
3943
* 1081a5b Initial 1
4044

4145
Repository state:
4246

43-
* 1081a5b (gh/ezyang/1/head)
47+
* fa3f7db (gh/ezyang/1/head)
48+
| Update A
49+
* 1081a5b
4450
| Initial 1
4551
* 5a32949 (gh/ezyang/1/base)
4652
| Initial 1 (base update)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from ghstack.test_prelude import *
2+
3+
init_test()
4+
5+
commit("AAA")
6+
(A,) = gh_submit("Initial")
7+
8+
# Record the correct state before corruption
9+
correct_head = git("rev-parse", "origin/gh/ezyang/1/head")
10+
11+
# Corrupt the remote head branch by pushing a wrong commit to it
12+
# We'll push an unrelated commit (just the tree, no proper parents)
13+
corrupted_commit = git("commit-tree", git("rev-parse", "master^{tree}"), "-m", "Corrupted")
14+
git("push", "origin", "--force", f"{corrupted_commit}:gh/ezyang/1/head")
15+
16+
# Verify the branch is actually corrupted
17+
assert git("rev-parse", "origin/gh/ezyang/1/head") == corrupted_commit
18+
19+
# Now submit with --no-skip --force and no local changes
20+
# This should fix the corrupted remote branch
21+
(A2,) = gh_submit("Fix", no_skip=True, force=True, check_invariants=False)
22+
23+
# Verify the head branch was restored to a valid state
24+
# It should have been updated (new commit), not rolled back
25+
fixed_head = git("rev-parse", "origin/gh/ezyang/1/head")
26+
assert fixed_head != corrupted_commit
27+
assert fixed_head != correct_head # Should be a new commit due to --no-skip
28+
29+
# Verify that the diff between head and base matches the diff in orig
30+
# This ensures the fix properly maintains diff integrity
31+
if is_direct():
32+
head_base_diff = git("diff", "origin/master", "origin/gh/ezyang/1/head")
33+
else:
34+
head_base_diff = git("diff", "origin/gh/ezyang/1/base", "origin/gh/ezyang/1/head")
35+
orig_diff = git("diff", "origin/gh/ezyang/1/orig~", "origin/gh/ezyang/1/orig")
36+
assert head_base_diff == orig_diff, "head/base diff should match orig/orig~ diff"
37+
38+
if is_direct():
39+
assert_github_state(
40+
"""\
41+
[O] #500 Commit AAA (gh/ezyang/1/head -> master)
42+
43+
This is commit AAA
44+
45+
* 889632c Fix
46+
* 94870d6 Corrupted
47+
48+
Repository state:
49+
50+
* 889632c (gh/ezyang/1/next, gh/ezyang/1/head)
51+
| Fix
52+
* 94870d6
53+
Corrupted
54+
"""
55+
)
56+
else:
57+
assert_github_state(
58+
"""\
59+
[O] #500 Commit AAA (gh/ezyang/1/head -> gh/ezyang/1/base)
60+
61+
Stack:
62+
* __->__ #500
63+
64+
This is commit AAA
65+
66+
* 889632c Fix
67+
* 94870d6 Corrupted
68+
69+
Repository state:
70+
71+
* 889632c (gh/ezyang/1/head)
72+
| Fix
73+
* 94870d6
74+
Corrupted
75+
"""
76+
)
77+
78+
ok()

0 commit comments

Comments
 (0)