-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Description
When checking out a file from a commit (via commit files view, pressing 'c'), lazygit does not warn or confirm when the local working copy has uncommitted modifications. This can result in accidental data loss.
Steps to Reproduce
- View a commit (press Enter on commit in commits view)
- Navigate to the commit files panel
- Select a file that has local uncommitted modifications
- Press 'c' (checkout file)
- File is immediately overwritten without confirmation
Expected Behavior
Similar to hard reset operations (PR #4704), checkout should:
- Detect if the target file has uncommitted changes
- Show confirmation dialog before overwriting
- Use the
ConfirmIfpattern already established in the codebase
Actual Behavior
File is immediately overwritten without warning, losing local uncommitted changes.
Code Location
pkg/gui/controllers/commits_files_controller.go:263-272
The checkout function directly calls CheckoutFile without any confirmation check.
Suggested Fix
Apply the same ConfirmIf pattern used for hard reset in refs_helper.go:268:
func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error {
fileHasChanges := /* check if node.GetPath() has uncommitted changes */
return self.c.ConfirmIf(fileHasChanges,
types.ConfirmOpts{
Title: self.c.Tr.Actions.CheckoutFile,
Prompt: self.c.Tr.CheckoutFileConfirmation,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.CheckoutFile)
_, to := self.context().GetFromAndToForDiff()
if err := self.c.Git().WorkingTree.CheckoutFile(to, node.GetPath()); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return nil
},
})
}Related
- PR Add confirmation for hard reset #4704 (Add confirmation for hard reset)
- Issue Add confirmation before reset --hard if there are local changes #3709 (Add confirmation before reset --hard if there are local changes)
Metadata
Metadata
Assignees
Labels
No labels