Skip to content

fix: preserve unrelated unstaged changes on conflict - #1483

Open
Sakshamm-Goyal wants to merge 2 commits into
evilmartians:masterfrom
Sakshamm-Goyal:fix/preserve-unrelated-unstaged-changes
Open

fix: preserve unrelated unstaged changes on conflict#1483
Sakshamm-Goyal wants to merge 2 commits into
evilmartians:masterfrom
Sakshamm-Goyal:fix/preserve-unrelated-unstaged-changes

Conversation

@Sakshamm-Goyal

@Sakshamm-Goyal Sakshamm-Goyal commented Aug 7, 2026

Copy link
Copy Markdown

Closes #1480

Context

When the hidden patch for a partially staged file conflicts with hook output, Lefthook resets the whole tracked worktree before replaying only the partial-file patch. That restores the conflicting file, but silently discards pre-existing unstaged changes in unrelated tracked files.

Changes

  • Save a full pre-hook unstaged patch alongside the partial-file patch.
  • Keep the existing partial patch on the normal successful restore path.
  • After conflict recovery resets hook output, replay the full patch so every pre-existing unstaged change is restored.
  • Remove both temporary patches and the auto-backup stash after a successful restore.
  • Add a real-Git regression covering a partially staged conflict plus an unrelated unstaged tracked file.

Validation

  • make test
  • affected restore integration scenarios with the race detector
  • all integration scripts except the timing-sensitive run_interrupt script in one race-enabled batch
  • run_interrupt separately with the race detector
  • make lint (0 issues)

AI usage

Prepared with Codex; the behavior is covered by the fail-first integration regression and repository test commands listed above.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "fix: preserve recovery error context" | Re-trigger Greptile

Context used:

  • Context used - AGENTS.md (source)

@Sakshamm-Goyal
Sakshamm-Goyal requested a review from mrexox as a code owner August 7, 2026 00:14
Comment thread internal/git/repo.go Outdated
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.

Unstaged changes in unrelated files are discarded by git checkout . when restoring hidden changes fails

1 participant