feat(git): GitWorkingCopy.discard() to drop local work and come back to the remote state #72

Merged
crapougnax merged 1 commit from feat/71-git-working-copy-discard into develop 2026-11-19 08:03:38 +00:00
Owner

Closes #71

What

GitWorkingCopy.discard() drops the local work and comes back to the state of the remote:

  • with a remote: fetches the branch, then checks it out by force and removes untracked files — commits not pushed, staged and unstaged changes and untracked files are dropped, ignored files are kept;
  • against a remote without the branch yet: back to an empty branch;
  • without a remote: drops pending changes only, back to the last commit;
  • same queue as the other operations; never writes to the remote.

The fetch of fastForward() moves to a fetch() helper shared by both.

Why

One commit per change, pushed at once and signed by the person who made it, needs a recovery when the remote moved in between: discard, apply the change again on the fresh state, push.

Tests

npx jest packages/git: 17 passed, 3 new (refused push then retry, empty remote, no remote). tsc --noEmit clean.

🤖 Generated with Claude Code

Closes #71 ## What `GitWorkingCopy.discard()` drops the local work and comes back to the state of the remote: - with a remote: fetches the branch, then checks it out by force and removes untracked files — commits not pushed, staged and unstaged changes and untracked files are dropped, ignored files are kept; - against a remote without the branch yet: back to an empty branch; - without a remote: drops pending changes only, back to the last commit; - same queue as the other operations; never writes to the remote. The fetch of `fastForward()` moves to a `fetch()` helper shared by both. ## Why One commit per change, pushed at once and signed by the person who made it, needs a recovery when the remote moved in between: discard, apply the change again on the fresh state, push. ## Tests `npx jest packages/git`: 17 passed, 3 new (refused push then retry, empty remote, no remote). `tsc --noEmit` clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(git): GitWorkingCopy.discard() to drop local work and come back to the remote state
All checks were successful
Quatrain Core CI / Monorepo Build, Tests & Quality Audit (push) Successful in 4m58s
Quatrain Core CI / Monorepo Build, Tests & Quality Audit (pull_request) Successful in 5m6s
Quatrain Core CI / Publish Changed Packages to npm (pull_request) Has been skipped
Quatrain Core CI / Publish Changed Packages to npm (push) Has been skipped
5a0429b593
An application that commits and pushes one change at a time needs a way out
when the remote refuses a push because someone pushed first. discard()
fetches the branch and resets the working copy to it: commits not pushed,
pending changes and untracked files are dropped, ignored files kept. Against
an empty remote it comes back to an empty branch; without a remote it drops
pending changes only. The remote is never written to.

Closes #71

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
crapougnax merged commit 5719f2544a into develop 2026-11-19 08:03:38 +00:00
crapougnax deleted branch feat/71-git-working-copy-discard 2026-11-19 08:03:38 +00:00
Sign in to join this conversation.
No description provided.