Skip to content

Commit aa23a6e

Browse files
authored
Add option to disable warning when amending last commit (#4640)
- **PR Description** Add an option in the User Config to disable the warning message when amending the last commit. Fixes #4636
2 parents aa331e5 + 708b30a commit aa23a6e

File tree

6 files changed

+41
-23
lines changed

6 files changed

+41
-23
lines changed

docs/Config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ gui:
7272
# When mouse events are captured, it's a little harder to select text: e.g. requiring you to hold the option key when on macOS.
7373
mouseEvents: true
7474

75+
# If true, do not show a warning when amending a commit.
76+
skipAmendWarning: false
77+
7578
# If true, do not show a warning when discarding changes in the staging view.
7679
skipDiscardChangeWarning: false
7780

pkg/config/app_config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ gui:
384384
# When mouse events are captured, it's a little harder to select text: e.g. requiring you to hold the option key when on macOS.
385385
mouseEvents: true
386386
387+
# If true, do not show a warning when amending a commit.
388+
skipAmendWarning: false
389+
387390
# If true, do not show a warning when discarding changes in the staging view.
388391
skipDiscardChangeWarning: false
389392

pkg/config/user_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type GuiConfig struct {
7474
// If true, capture mouse events.
7575
// When mouse events are captured, it's a little harder to select text: e.g. requiring you to hold the option key when on macOS.
7676
MouseEvents bool `yaml:"mouseEvents"`
77+
// If true, do not show a warning when amending a commit.
78+
SkipAmendWarning bool `yaml:"skipAmendWarning"`
7779
// If true, do not show a warning when discarding changes in the staging view.
7880
SkipDiscardChangeWarning bool `yaml:"skipDiscardChangeWarning"`
7981
// If true, do not show warning when applying/popping the stash
@@ -734,6 +736,7 @@ func GetDefaultConfig() *UserConfig {
734736
ScrollOffBehavior: "margin",
735737
TabWidth: 4,
736738
MouseEvents: true,
739+
SkipAmendWarning: false,
737740
SkipDiscardChangeWarning: false,
738741
SkipStashWarning: false,
739742
SidePanelWidth: 0.3333,

pkg/gui/controllers/files_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,17 +795,19 @@ func (self *FilesController) handleAmendCommitPress() error {
795795
},
796796
},
797797
})
798-
} else {
798+
} else if !self.c.UserConfig().Gui.SkipAmendWarning {
799799
self.c.Confirm(types.ConfirmOpts{
800800
Title: self.c.Tr.AmendLastCommitTitle,
801801
Prompt: self.c.Tr.SureToAmend,
802802
HandleConfirm: func() error {
803803
return doAmend()
804804
},
805805
})
806+
807+
return nil
806808
}
807809

808-
return nil
810+
return doAmend()
809811
}
810812

811813
func (self *FilesController) isResolvingConflicts() bool {

pkg/gui/controllers/local_commits_controller.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -717,35 +717,37 @@ func (self *LocalCommitsController) moveUp(selectedCommits []*models.Commit, sta
717717
}
718718

719719
func (self *LocalCommitsController) amendTo(commit *models.Commit) error {
720-
if self.isSelectedHeadCommit() {
721-
self.c.Confirm(types.ConfirmOpts{
722-
Title: self.c.Tr.AmendCommitTitle,
723-
Prompt: self.c.Tr.AmendCommitPrompt,
724-
HandleConfirm: func() error {
725-
return self.c.Helpers().WorkingTree.WithEnsureCommittableFiles(func() error {
726-
if err := self.c.Helpers().AmendHelper.AmendHead(); err != nil {
727-
return err
728-
}
729-
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
730-
})
731-
},
732-
})
720+
var handleCommit func() error
733721

734-
return nil
735-
}
736-
737-
self.c.Confirm(types.ConfirmOpts{
738-
Title: self.c.Tr.AmendCommitTitle,
739-
Prompt: self.c.Tr.AmendCommitPrompt,
740-
HandleConfirm: func() error {
722+
if self.isSelectedHeadCommit() {
723+
handleCommit = func() error {
724+
return self.c.Helpers().WorkingTree.WithEnsureCommittableFiles(func() error {
725+
if err := self.c.Helpers().AmendHelper.AmendHead(); err != nil {
726+
return err
727+
}
728+
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
729+
})
730+
}
731+
} else {
732+
handleCommit = func() error {
741733
return self.c.Helpers().WorkingTree.WithEnsureCommittableFiles(func() error {
742734
return self.c.WithWaitingStatus(self.c.Tr.AmendingStatus, func(gocui.Task) error {
743735
self.c.LogAction(self.c.Tr.Actions.AmendCommit)
744736
err := self.c.Git().Rebase.AmendTo(self.c.Model().Commits, self.context().GetView().SelectedLineIdx())
745737
return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
746738
})
747739
})
748-
},
740+
}
741+
}
742+
743+
if self.c.UserConfig().Gui.SkipAmendWarning {
744+
return handleCommit()
745+
}
746+
747+
self.c.Confirm(types.ConfirmOpts{
748+
Title: self.c.Tr.AmendCommitTitle,
749+
Prompt: self.c.Tr.AmendCommitPrompt,
750+
HandleConfirm: handleCommit,
749751
})
750752

751753
return nil

schema/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@
468468
"description": "If true, capture mouse events.\nWhen mouse events are captured, it's a little harder to select text: e.g. requiring you to hold the option key when on macOS.",
469469
"default": true
470470
},
471+
"skipAmendWarning": {
472+
"type": "boolean",
473+
"description": "If true, do not show a warning when amending a commit.",
474+
"default": false
475+
},
471476
"skipDiscardChangeWarning": {
472477
"type": "boolean",
473478
"description": "If true, do not show a warning when discarding changes in the staging view.",

0 commit comments

Comments
 (0)