Skip to content

Commit 9625ee8

Browse files
authored
Add confirmation for nuking the working tree (#4727)
- **PR Description** This is a small PR that extends the logic added in #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.
2 parents 1795cb9 + 238fdd5 commit 9625ee8

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

pkg/gui/controllers/workspace_reset_controller.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,26 @@ func (self *FilesController) createResetMenu() error {
3131
red.Sprint(nukeStr),
3232
},
3333
OnPress: func() error {
34-
self.c.LogAction(self.c.Tr.Actions.NukeWorkingTree)
35-
if err := self.c.Git().WorkingTree.ResetAndClean(); err != nil {
36-
return err
37-
}
34+
self.c.Confirm(
35+
types.ConfirmOpts{
36+
Title: self.c.Tr.Actions.NukeWorkingTree,
37+
Prompt: self.c.Tr.NukeTreeConfirmation,
38+
HandleConfirm: func() error {
39+
self.c.LogAction(self.c.Tr.Actions.NukeWorkingTree)
40+
if err := self.c.Git().WorkingTree.ResetAndClean(); err != nil {
41+
return err
42+
}
3843

39-
if self.c.UserConfig().Gui.AnimateExplosion {
40-
self.animateExplosion()
41-
}
44+
if self.c.UserConfig().Gui.AnimateExplosion {
45+
self.animateExplosion()
46+
}
4247

43-
self.c.Refresh(
44-
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
45-
)
48+
self.c.Refresh(
49+
types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}},
50+
)
51+
return nil
52+
},
53+
})
4654
return nil
4755
},
4856
Key: 'x',

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ type TranslationSet struct {
782782
SoftResetPrompt string
783783
UpstreamGone string
784784
NukeDescription string
785+
NukeTreeConfirmation string
785786
DiscardStagedChangesDescription string
786787
EmptyOutput string
787788
Patch string
@@ -1832,6 +1833,7 @@ func EnglishTranslationSet() *TranslationSet {
18321833
CheckoutAutostashPrompt: "Are you sure you want to checkout '%s'? An auto-stash will be performed if necessary.",
18331834
UpstreamGone: "(upstream gone)",
18341835
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).",
1836+
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.",
18351837
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",
18361838
EmptyOutput: "<Empty output>",
18371839
Patch: "Patch",

0 commit comments

Comments
 (0)