mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-14 00:21:48 +03:00
Add confirmation for hard reset when there are uncommitted changes
This commit is contained in:
@ -248,9 +248,16 @@ func (self *RefsHelper) CreateGitResetMenu(name string, ref string) error {
|
||||
style.FgRed.Sprintf("reset --%s %s", row.strength, name),
|
||||
},
|
||||
OnPress: func() error {
|
||||
return self.c.ConfirmIf(row.strength == "hard" && IsWorkingTreeDirty(self.c.Model().Files),
|
||||
types.ConfirmOpts{
|
||||
Title: self.c.Tr.Actions.HardReset,
|
||||
Prompt: self.c.Tr.ResetHardConfirmation,
|
||||
HandleConfirm: func() error {
|
||||
self.c.LogAction("Reset")
|
||||
return self.ResetToRef(ref, row.strength, []string{})
|
||||
},
|
||||
})
|
||||
},
|
||||
Key: row.key,
|
||||
Tooltip: row.tooltip,
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
@ -150,6 +151,11 @@ func (self *FilesController) createResetMenu() error {
|
||||
red.Sprint("git reset --hard HEAD"),
|
||||
},
|
||||
OnPress: func() error {
|
||||
return self.c.ConfirmIf(helpers.IsWorkingTreeDirty(self.c.Model().Files),
|
||||
types.ConfirmOpts{
|
||||
Title: self.c.Tr.Actions.HardReset,
|
||||
Prompt: self.c.Tr.ResetHardConfirmation,
|
||||
HandleConfirm: func() error {
|
||||
self.c.LogAction(self.c.Tr.Actions.HardReset)
|
||||
if err := self.c.Git().WorkingTree.ResetHard("HEAD"); err != nil {
|
||||
return err
|
||||
@ -160,6 +166,8 @@ func (self *FilesController) createResetMenu() error {
|
||||
)
|
||||
return nil
|
||||
},
|
||||
})
|
||||
},
|
||||
Key: 'h',
|
||||
},
|
||||
}
|
||||
|
@ -479,6 +479,7 @@ type TranslationSet struct {
|
||||
ResetSoftTooltip string
|
||||
ResetMixedTooltip string
|
||||
ResetHardTooltip string
|
||||
ResetHardConfirmation string
|
||||
PressEnterToReturn string
|
||||
ViewStashOptions string
|
||||
ViewStashOptionsTooltip string
|
||||
@ -1502,6 +1503,7 @@ func EnglishTranslationSet() *TranslationSet {
|
||||
ResetSoftTooltip: "Reset HEAD to the chosen commit, and keep the changes between the current and chosen commit as staged changes.",
|
||||
ResetMixedTooltip: "Reset HEAD to the chosen commit, and keep the changes between the current and chosen commit as unstaged changes.",
|
||||
ResetHardTooltip: "Reset HEAD to the chosen commit, and discard all changes between the current and chosen commit, as well as all current modifications in the working tree.",
|
||||
ResetHardConfirmation: "Are you sure you want to do a hard reset? This will discard all uncommitted changes (both staged and unstaged), which is not undoable.",
|
||||
ViewResetOptions: `Reset`,
|
||||
FileResetOptionsTooltip: "View reset options for working tree (e.g. nuking the working tree).",
|
||||
FixupTooltip: "Meld the selected commit into the commit below it. Similar to squash, but the selected commit's message will be discarded.",
|
||||
|
@ -97,6 +97,11 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Title(Equals("Reset to origin/hard-branch")).
|
||||
Select(Contains("Hard reset")).
|
||||
Confirm()
|
||||
|
||||
t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Hard reset")).
|
||||
Content(Contains("Are you sure you want to do a hard reset?")).
|
||||
Confirm()
|
||||
})
|
||||
t.Views().Commits().Lines(Contains("hard commit"))
|
||||
t.Views().Files().IsEmpty()
|
||||
|
Reference in New Issue
Block a user