mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Merge 9671755ada into 8924bca76f
This commit is contained in:
commit
8c66a8cee8
|
|
@ -179,6 +179,22 @@ func (self *CommitsHelper) ClearPreservedCommitMessage() {
|
|||
self.c.Contexts().CommitMessage.SetPreservedMessageAndLogError("")
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) PreserveCommitMessageForCommit(commitHash string) error {
|
||||
message, err := self.c.Git().Commit.GetCommitMessage(commitHash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
summary, description := self.SplitCommitMessageAndDescription(message)
|
||||
preservedMessage := summary
|
||||
if description != "" {
|
||||
preservedMessage += "\n" + description
|
||||
}
|
||||
|
||||
self.c.Contexts().CommitMessage.SetPreservedMessageAndLogError(preservedMessage)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) HandleCommitConfirm() error {
|
||||
summary, description := self.getCommitSummary(), self.getCommitDescription()
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ type reflogAction struct {
|
|||
kind ReflogActionKind
|
||||
from string
|
||||
to string
|
||||
msg bool
|
||||
}
|
||||
|
||||
func (self *UndoController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
|
|
@ -94,7 +95,15 @@ func (self *UndoController) reflogUndo() error {
|
|||
HandleConfirm: func() error {
|
||||
self.c.LogAction(self.c.Tr.Actions.Undo)
|
||||
return self.c.WithWaitingStatus(undoingStatus, func(gocui.Task) error {
|
||||
return self.c.Helpers().Refs.ResetToRef(action.from, "soft", undoEnvVars)
|
||||
if err := self.c.Helpers().Refs.ResetToRef(action.from, "soft", undoEnvVars); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if action.msg {
|
||||
return self.c.Helpers().Commits.PreserveCommitMessageForCommit(action.to)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
@ -160,10 +169,18 @@ func (self *UndoController) reflogRedo() error {
|
|||
Prompt: fmt.Sprintf(self.c.Tr.HardResetAutostashPrompt, utils.ShortHash(action.to)),
|
||||
HandleConfirm: func() error {
|
||||
self.c.LogAction(self.c.Tr.Actions.Redo)
|
||||
return self.hardResetWithAutoStash(action.to, hardResetOptions{
|
||||
if err := self.hardResetWithAutoStash(action.to, hardResetOptions{
|
||||
EnvVars: redoEnvVars,
|
||||
WaitingStatus: redoingStatus,
|
||||
})
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if action.msg {
|
||||
self.c.Helpers().Commits.ClearPreservedCommitMessage()
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
})
|
||||
return true, nil
|
||||
|
|
@ -219,7 +236,9 @@ func (self *UndoController) parseReflogForActions(onUserAction func(counter int,
|
|||
rebaseFinishCommitHash = reflogCommit.Hash()
|
||||
} else if ok, match := utils.FindStringSubmatch(reflogCommit.Name, `^checkout: moving from ([\S]+) to ([\S]+)`); ok {
|
||||
action = &reflogAction{kind: CHECKOUT, from: match[1], to: match[2]}
|
||||
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^commit|^reset: moving to|^pull`); ok {
|
||||
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^commit`); ok {
|
||||
action = &reflogAction{kind: COMMIT, from: prevCommitHash, to: reflogCommit.Hash(), msg: true}
|
||||
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^reset: moving to|^pull`); ok {
|
||||
action = &reflogAction{kind: COMMIT, from: prevCommitHash, to: reflogCommit.Hash()}
|
||||
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok {
|
||||
// if we're here then we must be currently inside an interactive rebase
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
shell.CreateFileAndAdd("other-file", "other-file-1")
|
||||
shell.Commit("one")
|
||||
shell.CreateFileAndAdd("file", "file-1")
|
||||
shell.Commit("two")
|
||||
shell.RunCommand([]string{"git", "commit", "-m", "two", "-m", "first paragraph\n\nsecond paragraph"})
|
||||
shell.UpdateFile("other-file", "other-file-2")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
|
|
@ -62,6 +62,15 @@ var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
Equals(" M other-file"),
|
||||
)
|
||||
|
||||
t.Views().Files().Focus().
|
||||
Press(keys.Files.CommitChanges)
|
||||
|
||||
t.ExpectPopup().CommitMessagePanel().
|
||||
Content(Equals("two")).
|
||||
SwitchToDescription().
|
||||
Content(Equals("first paragraph\n\nsecond paragraph")).
|
||||
Cancel()
|
||||
|
||||
t.Views().Commits().Focus().
|
||||
Press(keys.Universal.Redo).
|
||||
Tap(confirmRedo).
|
||||
|
|
@ -70,6 +79,8 @@ var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
Contains("one"),
|
||||
)
|
||||
|
||||
t.FileSystem().PathNotPresent(".git/LAZYGIT_PENDING_COMMIT")
|
||||
|
||||
t.Views().Files().
|
||||
Lines(
|
||||
Equals(" M other-file"),
|
||||
|
|
@ -98,7 +109,7 @@ var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
Press(keys.Universal.Redo).
|
||||
Tap(confirmRedo)
|
||||
|
||||
t.Views().Commits().
|
||||
t.Views().Commits().Focus().
|
||||
Lines(
|
||||
Contains("two"),
|
||||
Contains("one"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue