Skip to content

fix(sync): Protect unsubmitted merged branches#1129

Merged
abhinav merged 1 commit intomainfrom
fix-repo-sync-merged-heads
Apr 26, 2026
Merged

fix(sync): Protect unsubmitted merged branches#1129
abhinav merged 1 commit intomainfrom
fix-repo-sync-merged-heads

Conversation

@abhinav
Copy link
Copy Markdown
Owner

@abhinav abhinav commented Apr 26, 2026

repo sync should not delete a branch just because its CR is merged.
If the local branch has commits that were never part of the merged CR,
removing it can discard work that has not reached the forge.
This protects the case where the forge merged an older CR head,
while the local branch moved on afterward.

Use the forge-reported CR head as the deletion interlock.
Merged branches are deleted automatically only when the local head is the
same commit,
or when local Git can prove that the forge head contains the local head.
Otherwise sync keeps the branch in non-interactive mode
and prompts before deletion when interaction is available.

The compact forge status query now returns both state and head SHA,
so the safety check reuses the existing status request without adding
another network call.

Test note:

The renamed-branch sync script now re-submits the branch after rename.
That keeps its original coverage focused on issue #401: deleting the
old tracking ref, origin/feature1, when the local branch has been
renamed to feat1. Without re-submitting, the local branch contains an
unsubmitted commit and correctly exercises the new #1107 skip path
instead of the renamed-tracking-ref deletion path.

Resolves #1107

@abhinav
Copy link
Copy Markdown
Owner Author

abhinav commented Apr 26, 2026

This change is part of the following stack:

Change managed by git-spice.

@abhinav abhinav force-pushed the fix-repo-sync-merged-heads branch from 6d9a98d to fa885cc Compare April 26, 2026 21:00
`repo sync` should not delete a branch just because its CR is merged.
If the local branch has commits that were never part of the merged CR,
removing it can discard work that has not reached the forge.
This protects the case where the forge merged an older CR head,
while the local branch moved on afterward.

Use the forge-reported CR head as the deletion interlock.
Merged branches are deleted automatically only when the local head is the
same commit,
or when local Git can prove that the forge head contains the local head.
Otherwise sync keeps the branch in non-interactive mode
and prompts before deletion when interaction is available.

The compact forge status query now returns both state and head SHA,
so the safety check reuses the existing status request without adding
another network call.

Resolves #1107
@abhinav abhinav force-pushed the fix-repo-sync-merged-heads branch from fa885cc to 9522445 Compare April 26, 2026 21:10
@abhinav abhinav enabled auto-merge (squash) April 26, 2026 21:18
@abhinav abhinav merged commit 3d2748f into main Apr 26, 2026
25 of 31 checks passed
@abhinav abhinav deleted the fix-repo-sync-merged-heads branch April 26, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commit(s) lost on repo-sync with merged branch

1 participant