Skip to content

Conversation

@stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Jan 1, 2026

Checking out a file discards all local modifications to that file; checking out a directory discards modifications to all files in that directory. This can result in lost work if the user isn't aware of this.

Instead of showing a confirmation (to which the user might press enter too hastily, still losing their work), or showing a menu with auto-stash/discard options, we simply show an error. The assumption is that this is an unusual situation that users won't run into often, and if they do, it's easy enough to manually address it by stashing or discarding the changes as appropriate.

Fixes #5142.

@stefanhaller stefanhaller added the enhancement New feature or request label Jan 1, 2026
@codacy-production
Copy link

codacy-production bot commented Jan 1, 2026

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for d34266d1 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (d34266d) Report Missing Report Missing Report Missing
Head commit (3ccd33b) 59389 51716 87.08%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#5154) 48 48 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@KJ7LNW
Copy link

KJ7LNW commented Jan 1, 2026

I wonder if it should be a super trivial feature that just completely blocks the user and tells them "Checkout is blocked by existing modifications, address those first"

I think this case is unusual enough that if they accidentally hit c in that directory, we don't want them to lose what they're working on even if they press enter. I'm suggesting this because I find my lazygit muscle memory sometimes too fast to press Enter because in certain key sequences I'm used to forcing an override of something.

Perhaps they should be forced to navigate to 2 and properly manage files in the way that they are normally used to doing (s, d, etc...)

This is also probably the simplest implementation and easiest to release.

@stefanhaller stefanhaller force-pushed the confirmation-for-checkout-file branch from e3aeb63 to 3936224 Compare January 3, 2026 10:37
@stefanhaller stefanhaller changed the title Show a confirmation when checking out a file would overwrite local modifications Show an error when checking out a file would overwrite local modifications Jan 3, 2026
@stefanhaller stefanhaller marked this pull request as ready for review January 3, 2026 10:43
@stefanhaller
Copy link
Collaborator Author

@KJ7LNW Fair enough. Please review.

@KJ7LNW
Copy link

KJ7LNW commented Jan 3, 2026

I built this PR and tested it directly. It seems to work well, and I like the implementation as well. Feel free to merge when ready!

-Eric

@stefanhaller stefanhaller enabled auto-merge January 3, 2026 19:09
@stefanhaller stefanhaller force-pushed the confirmation-for-checkout-file branch from 3936224 to 3ccd33b Compare January 3, 2026 19:10
@stefanhaller stefanhaller merged commit 810f6b2 into master Jan 3, 2026
13 checks passed
@stefanhaller stefanhaller deleted the confirmation-for-checkout-file branch January 3, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checkout file from commit lacks confirmation when local changes exist

3 participants