Skip to content

Guard PR worktree resets from local work - #135

Merged
chihsuan merged 4 commits into
mainfrom
fix/worktree-reset-local-commits
Jun 30, 2026
Merged

Guard PR worktree resets from local work#135
chihsuan merged 4 commits into
mainfrom
fix/worktree-reset-local-commits

Conversation

@chihsuan

@chihsuan chihsuan commented Jun 30, 2026

Copy link
Copy Markdown
Member

Context

Explicit-base PR redispatch hard resets a reused worktree, which can drop dirty/untracked files or unpushed commits. Failing fast on that state avoids the data loss but stalls the rework and blocks it from adopting the authoritative remote head (e.g. a commit pushed to the PR via the GitHub UI).

TL;DR

PR worktree resets now snapshot local-only work to a recoverable ref, then proceed.

Summary

  • Before the reuse reset, snapshot the worktree's unpushed commits plus uncommitted and untracked changes to refs/symphony/orphaned/<sha> (a commit-tree over a throwaway index, leaving the live index/worktree untouched).
  • Proceed with the reset so the rework still adopts the remote head — no stalls, and a UI-pushed head still wins.
  • Mirror the backup on remote workers inside a || true subshell so a backup failure can never abort the set -eu prepare script before the reset.
  • Update local and remote reset tests to assert the snapshot-and-reset behavior and recoverability of each case.

Alternatives

  • Fail fast on unsafe state (clearer, but stalls reworks with no self-heal and blocks adopting a UI-pushed head).
  • Auto-stash only tracked changes: misses untracked files that a colliding checkout -f would clobber.

Test Plan

  • make all
  • mix test test/symphony_elixir/workspace_and_config_test.exs test/symphony_elixir/workspace_test.exs
  • git diff --check origin/main...HEAD
  • PR CI

@chihsuan
chihsuan requested a review from Copilot June 30, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chihsuan
chihsuan force-pushed the fix/worktree-reset-local-commits branch from b8d8c58 to b66f708 Compare June 30, 2026 08:16
Summary:
- Refuse explicit-base worktree reuse when dirty changes are present.
- Refuse reset when HEAD has commits not present on any remote.
- Add local and remote regression coverage.

Rationale:
- Hard resets during rework dispatch could silently drop committed work that had not been pushed.

Tests:
- mix test test/symphony_elixir/workspace_and_config_test.exs test/symphony_elixir/workspace_test.exs.
- git diff --check.
@chihsuan
chihsuan force-pushed the fix/worktree-reset-local-commits branch from b66f708 to 2546531 Compare June 30, 2026 08:24
@chihsuan
chihsuan merged commit 01bfd2f into main Jun 30, 2026
12 checks passed
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.

2 participants