Skip to content

Commit

Permalink
Update for PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellanata authored Jan 16, 2025
1 parent f601b1c commit 01b134a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 63 deletions.
7 changes: 0 additions & 7 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,6 @@ git:
# The commit message to use for a squash merge commit. Can contain "{{selectedRef}}" and "{{currentBranch}}" placeholders.
squashMergeMessage: Squash merge {{selectedRef}} into {{currentBranch}}

# Config relating to undoing
undo:
# Wether to use hard or soft git reset when undoing commits
commitReset: hard
# Wether to use hard or soft git reset when undoing rebases
rebaseReset: hard

# list of branches that are considered 'main' branches, used when displaying commits
mainBranches:
- master
Expand Down
13 changes: 0 additions & 13 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ type GitConfig struct {
Commit CommitConfig `yaml:"commit"`
// Config relating to merging
Merging MergingConfig `yaml:"merging"`
// Config relating to undoing
Undo UndoConfig `yaml:"undo"`
// list of branches that are considered 'main' branches, used when displaying commits
MainBranches []string `yaml:"mainBranches" jsonschema:"uniqueItems=true"`
// Prefix to use when skipping hooks. E.g. if set to 'WIP', then pre-commit hooks will be skipped when the commit message starts with 'WIP'
Expand Down Expand Up @@ -316,13 +314,6 @@ type MergingConfig struct {
SquashMergeMessage string `yaml:"squashMergeMessage"`
}

type UndoConfig struct {
// One of: 'hard' | 'soft'
CommitReset string `yaml:"commitReset" jsonschema:"enum=hard,enum=soft"`
// One of: 'hard' | 'soft'
RebaseReset string `yaml:"rebaseReset" jsonschema:"enum=hard,enum=soft"`
}

type LogConfig struct {
// One of: 'date-order' | 'author-date-order' | 'topo-order' | 'default'
// 'topo-order' makes it easier to read the git log graph, but commits may not
Expand Down Expand Up @@ -777,10 +768,6 @@ func GetDefaultConfig() *UserConfig {
Args: "",
SquashMergeMessage: "Squash merge {{selectedRef}} into {{currentBranch}}",
},
Undo: UndoConfig{
CommitReset: "hard",
RebaseReset: "hard",
},
Log: LogConfig{
Order: "topo-order",
ShowGraph: "always",
Expand Down
71 changes: 34 additions & 37 deletions pkg/gui/controllers/undo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,29 @@ func (self *UndoController) reflogUndo() error {
}

switch action.kind {
case COMMIT, REBASE:
var resetMode string
switch action.kind {
case COMMIT:
resetMode = self.c.UserConfig().Git.Undo.CommitReset
case REBASE:
resetMode = self.c.UserConfig().Git.Undo.RebaseReset
}

var resetPrompt string
switch resetMode {
case "hard":
resetPrompt = self.c.Tr.HardResetAutostashPrompt
case "soft":
resetPrompt = self.c.Tr.SoftResetAutostashPrompt
}
case COMMIT:
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.Actions.Undo,
Prompt: fmt.Sprintf(self.c.Tr.SoftResetAutostashPrompt, action.from),
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Undo)
return self.resetWithAutoStash(action.from, resetOptions{
Mode: "soft",
EnvVars: undoEnvVars,
WaitingStatus: undoingStatus,
})
},
})
return true, nil

// 3. Use those in the confirm step
case REBASE:
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.Actions.Undo,
Prompt: fmt.Sprintf(resetPrompt, action.from),
Prompt: fmt.Sprintf(self.c.Tr.HardResetAutostashPrompt, action.from),
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Undo)
return self.resetWithAutoStash(action.from, resetOptions{
Mode: resetMode,
Mode: "hard",
EnvVars: undoEnvVars,
WaitingStatus: undoingStatus,
})
Expand Down Expand Up @@ -160,30 +158,29 @@ func (self *UndoController) reflogRedo() error {
}

switch action.kind {
case COMMIT, REBASE:
var resetMode string
switch action.kind {
case COMMIT:
resetMode = self.c.UserConfig().Git.Undo.CommitReset
case REBASE:
resetMode = self.c.UserConfig().Git.Undo.RebaseReset
}

var resetPrompt string
switch resetMode {
case "hard":
resetPrompt = self.c.Tr.HardResetAutostashPrompt
case "soft":
resetPrompt = self.c.Tr.SoftResetAutostashPrompt
}
case COMMIT:
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.Actions.Redo,
Prompt: fmt.Sprintf(self.c.Tr.SoftResetAutostashPrompt, action.to),
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Redo)
return self.resetWithAutoStash(action.to, resetOptions{
Mode: "soft",
EnvVars: redoEnvVars,
WaitingStatus: redoingStatus,
})
},
})
return true, nil

case REBASE:
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.Actions.Redo,
Prompt: fmt.Sprintf(resetPrompt, action.to),
Prompt: fmt.Sprintf(self.c.Tr.HardResetAutostashPrompt, action.to),
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Redo)
return self.resetWithAutoStash(action.to, resetOptions{
Mode: resetMode,
Mode: "hard",
EnvVars: redoEnvVars,
WaitingStatus: redoingStatus,
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ var tests = []*components.IntegrationTest{
ui.SwitchTabFromMenu,
ui.SwitchTabWithPanelJumpKeys,
undo.UndoCheckoutAndDrop,
undo.UndoCommitSoft,
undo.UndoCommit,
undo.UndoDrop,
worktree.AddFromBranch,
worktree.AddFromBranchDetached,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import (
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var UndoCommitSoft = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Undo/redo a commit using soft reset",
var UndoCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Undo/redo a commit",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.Undo.CommitReset = "soft"
},
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("one")
shell.CreateFileAndAdd("file", "content1")
Expand Down

0 comments on commit 01b134a

Please sign in to comment.