Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 45 additions & 24 deletions pkg/gui/controllers/workspace_reset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ func (self *FilesController) createResetMenu() error {
red.Sprint("git checkout -- ."),
},
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardUnstagedFileChanges)
if err := self.c.Git().WorkingTree.DiscardAnyUnstagedFileChanges(); err != nil {
return err
}
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.DiscardAnyUnstagedChanges,
Prompt: self.c.Tr.DiscardAnyUnstagedChangesConfirmation,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardUnstagedFileChanges)
if err := self.c.Git().WorkingTree.DiscardAnyUnstagedFileChanges(); err != nil {
return err
}

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: 'u',
Expand All @@ -80,14 +87,21 @@ func (self *FilesController) createResetMenu() error {
red.Sprint("git clean -fd"),
},
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RemoveUntrackedFiles)
if err := self.c.Git().WorkingTree.RemoveUntrackedFiles(); err != nil {
return err
}
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.DiscardUntrackedFiles,
Prompt: self.c.Tr.DiscardUntrackedFilesConfirmation,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.RemoveUntrackedFiles)
if err := self.c.Git().WorkingTree.RemoveUntrackedFiles(); err != nil {
return err
}

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: 'c',
Expand All @@ -99,20 +113,27 @@ func (self *FilesController) createResetMenu() error {
},
Tooltip: self.c.Tr.DiscardStagedChangesDescription,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.RemoveStagedFiles)
if !self.c.Helpers().WorkingTree.IsWorkingTreeDirtyExceptSubmodules() {
return errors.New(self.c.Tr.NoTrackedStagedFilesStash)
}
if err := self.c.Git().Stash.SaveStagedChanges("[lazygit] tmp stash"); err != nil {
return err
}
if err := self.c.Git().Stash.DropNewest(); err != nil {
return err
}
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.DiscardStagedChanges,
Prompt: self.c.Tr.DiscardStagedChangesConfirmation,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.RemoveStagedFiles)
if err := self.c.Git().Stash.SaveStagedChanges("[lazygit] tmp stash"); err != nil {
return err
}
if err := self.c.Git().Stash.DropNewest(); err != nil {
return err
}

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: 'S',
Expand Down
6 changes: 6 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@ type TranslationSet struct {
NukeDescription string
NukeTreeConfirmation string
DiscardStagedChangesDescription string
DiscardAnyUnstagedChangesConfirmation string
DiscardUntrackedFilesConfirmation string
DiscardStagedChangesConfirmation string
EmptyOutput string
Patch string
CustomPatch string
Expand Down Expand Up @@ -1947,6 +1950,9 @@ func EnglishTranslationSet() *TranslationSet {
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",
DiscardAnyUnstagedChangesConfirmation: "Are you sure you want to discard all unstaged changes? This is not undoable.",
DiscardUntrackedFilesConfirmation: "Are you sure you want to discard all untracked files? This is not undoable.",
DiscardStagedChangesConfirmation: "Are you sure you want to discard all staged changes? This is not undoable.",
EmptyOutput: "<Empty output>",
Patch: "Patch",
CustomPatch: "Custom patch",
Expand Down
5 changes: 5 additions & 0 deletions pkg/integration/tests/file/discard_staged_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ var DiscardStagedChanges = NewIntegrationTest(NewIntegrationTestArgs{

t.ExpectPopup().Menu().Title(Equals("")).Select(Contains("Discard staged changes")).Confirm()

t.ExpectPopup().Confirmation().
Title(Equals("Discard staged changes")).
Content(Equals("Are you sure you want to discard all staged changes? This is not undoable.")).
Confirm()

// staged file has been removed
t.Views().Files().
Lines(
Expand Down