Skip to content

Conversation

@majiayu000
Copy link

Summary

This PR fixes #5142 by adding a confirmation dialog when checking out a file from a commit that has uncommitted local changes.

Changes

  • Added confirmation check in pkg/gui/controllers/commits_files_controller.go:285-305
    • Uses ConfirmIf pattern to detect files with staged or unstaged changes
    • Only shows confirmation dialog when local changes exist
  • Added i18n strings (CheckoutFileFromCommitTitle and CheckoutFileFromCommitPrompt) in pkg/i18n/english.go
  • Added integration test CheckoutFileFromCommitWithLocalChanges to verify the confirmation behavior

Test Plan

  • ✅ Code compiles successfully
  • ✅ All files properly formatted with gofmt
  • ✅ Integration test added to verify the confirmation dialog appears when expected
  • ✅ Follows the same ConfirmIf pattern used elsewhere in the codebase (similar to PR Add confirmation for hard reset #4704)

Generated with Claude Code

Add confirmation dialog when checking out a file from a commit that has
uncommitted local changes, preventing accidental data loss.

Implementation:
- Check if file has staged or unstaged changes using ConfirmIf pattern
- Show confirmation dialog only when local changes exist
- Add i18n strings for dialog title and prompt
- Add integration test to verify behavior

Fixes jesseduffield#5142

Signed-off-by: majiayu000 <[email protected]>
@stefanhaller
Copy link
Collaborator

@majiayu000 Sorry, I didn't see your PR before I started working on mine (#5154). I'll close this one, as mine also works correctly for checking out directories.

@majiayu000 majiayu000 deleted the fix-5142-checkout-file-from-commit-lack-1230-1416 branch January 1, 2026 13:26
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.

Checkout file from commit lacks confirmation when local changes exist

2 participants