|
| 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