1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

Add confirmation for nuking the working tree (#4727)

- **PR Description**

This is a small PR that extends the logic added in
https://github.com/jesseduffield/lazygit/pull/4704

There were many reports of users accidentally resetting the working tree
using the reset commands and a nice change was added by @stefanhaller to
prompt for confirmation on those actions but the "Nuke working tree"
option was not covered by the PR.

I believe this one is actually one of the most important options to
prompt because it's by default the first one on the list. I myself
triggered it once when trying to discard a single file while unknowingly
having caps-lock enabled as I thought I was confirming the single file
discard option.
This commit is contained in:
Stefan Haller
2025-07-13 15:01:22 +02:00
committed by GitHub
2 changed files with 20 additions and 10 deletions

View File

@ -31,18 +31,26 @@ func (self *FilesController) createResetMenu() error {
red.Sprint(nukeStr),
},
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.NukeWorkingTree)
if err := self.c.Git().WorkingTree.ResetAndClean(); err != nil {
return err
}
self.c.Confirm(
types.ConfirmOpts{
Title: self.c.Tr.Actions.NukeWorkingTree,
Prompt: self.c.Tr.NukeTreeConfirmation,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.NukeWorkingTree)
if err := self.c.Git().WorkingTree.ResetAndClean(); err != nil {
return err
}
if self.c.UserConfig().Gui.AnimateExplosion {
self.animateExplosion()
}
if self.c.UserConfig().Gui.AnimateExplosion {
self.animateExplosion()
}
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
self.c.Refresh(
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
)
return nil
},
})
return nil
},
Key: 'x',

View File

@ -782,6 +782,7 @@ type TranslationSet struct {
SoftResetPrompt string
UpstreamGone string
NukeDescription string
NukeTreeConfirmation string
DiscardStagedChangesDescription string
EmptyOutput string
Patch string
@ -1832,6 +1833,7 @@ func EnglishTranslationSet() *TranslationSet {
CheckoutAutostashPrompt: "Are you sure you want to checkout '%s'? An auto-stash will be performed if necessary.",
UpstreamGone: "(upstream gone)",
NukeDescription: "If you want to make all the changes in the worktree go away, this is the way to do it. If there are dirty submodule changes this will stash those changes in the submodule(s).",
NukeTreeConfirmation: "Are you sure you want to nuke the working tree? This will discard all changes in the worktree (staged, unstaged and untracked), which is not undoable.",
DiscardStagedChangesDescription: "This will create a new stash entry containing only staged files and then drop it, so that the working tree is left with only unstaged changes",
EmptyOutput: "<Empty output>",
Patch: "Patch",