Skip to content

Commit

Permalink
Mention auto-stash in the first confirmation popup
Browse files Browse the repository at this point in the history
There's no need to prompt the user twice.
  • Loading branch information
jesseduffield committed Jan 17, 2025
1 parent 25d5dc2 commit 98d62ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
40 changes: 16 additions & 24 deletions pkg/gui/controllers/undo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (self *UndoController) reflogUndo() error {
case CHECKOUT:
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.Actions.Undo,
Prompt: fmt.Sprintf(self.c.Tr.CheckoutPrompt, action.from),
Prompt: fmt.Sprintf(self.c.Tr.CheckoutAutostashPrompt, action.from),
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Undo)
return self.c.Helpers().Refs.CheckoutRef(action.from, types.CheckoutRefOptions{
Expand Down Expand Up @@ -172,7 +172,7 @@ func (self *UndoController) reflogRedo() error {
case CHECKOUT:
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.Actions.Redo,
Prompt: fmt.Sprintf(self.c.Tr.CheckoutPrompt, action.to),
Prompt: fmt.Sprintf(self.c.Tr.CheckoutAutostashPrompt, action.to),
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Redo)
return self.c.Helpers().Refs.CheckoutRef(action.to, types.CheckoutRefOptions{
Expand Down Expand Up @@ -257,31 +257,23 @@ func (self *UndoController) hardResetWithAutoStash(commitHash string, options ha
return self.c.Helpers().Refs.ResetToRef(commitHash, "hard", options.EnvVars)
}

// if we have any modified tracked files we need to ask the user if they want us to stash for them
// if we have any modified tracked files we need to auto-stash
dirtyWorkingTree := self.c.Helpers().WorkingTree.IsWorkingTreeDirty()
if dirtyWorkingTree {
// offer to autostash changes
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.AutoStashTitle,
Prompt: self.c.Tr.AutoStashPrompt,
HandleConfirm: func() error {
return self.c.WithWaitingStatus(options.WaitingStatus, func(gocui.Task) error {
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitHash); err != nil {
return err
}
if err := reset(); err != nil {
return err
}

err := self.c.Git().Stash.Pop(0)
if err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{})
})
},
return self.c.WithWaitingStatus(options.WaitingStatus, func(gocui.Task) error {
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitHash); err != nil {
return err
}
if err := reset(); err != nil {
return err
}

err := self.c.Git().Stash.Pop(0)
if err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{})
})
return nil
}

return self.c.WithWaitingStatus(options.WaitingStatus, func(gocui.Task) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ type TranslationSet struct {
ConfirmRevertCommit string
RewordInEditorTitle string
RewordInEditorPrompt string
CheckoutPrompt string
CheckoutAutostashPrompt string
HardResetAutostashPrompt string
SoftResetPrompt string
UpstreamGone string
Expand Down Expand Up @@ -1747,7 +1747,7 @@ func EnglishTranslationSet() *TranslationSet {
RewordInEditorPrompt: "Are you sure you want to reword this commit in your editor?",
HardResetAutostashPrompt: "Are you sure you want to hard reset to '%s'? An auto-stash will be performed if necessary.",
SoftResetPrompt: "Are you sure you want to soft reset to '%s'?",
CheckoutPrompt: "Are you sure you want to checkout '%s'?",
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).",
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",
Expand Down
11 changes: 1 addition & 10 deletions pkg/integration/tests/undo/undo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
Confirm()
}

confirmAutoSquash := func() {
t.ExpectPopup().Confirmation().
Title(Equals("Autostash?")).
Content(MatchesRegexp(`You must stash and pop your changes to bring them across\. Do this automatically\? \(enter\/esc\)`)).
Confirm()
}

t.Views().Files().
Lines(
Contains(" M other-file"),
Expand All @@ -71,7 +64,6 @@ var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
t.Views().Commits().Focus().
Press(keys.Universal.Redo).
Tap(confirmRedo).
Tap(confirmAutoSquash).
Lines(
Contains("two").IsSelected(),
Contains("one"),
Expand Down Expand Up @@ -102,8 +94,7 @@ var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
Contains(" M other-file"),
).
Press(keys.Universal.Redo).
Tap(confirmRedo).
Tap(confirmAutoSquash)
Tap(confirmRedo)

t.Views().Commits().
Lines(
Expand Down

0 comments on commit 98d62ad

Please sign in to comment.