1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00

Merge pull request #2341 from knutwalker/commit-verbose

This commit is contained in:
Jesse Duffield 2023-01-01 13:57:49 +11:00 committed by GitHub
commit 1bb138c79c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View File

@ -67,6 +67,7 @@ git:
useConfig: false useConfig: false
commit: commit:
signOff: false signOff: false
verbose: false
merging: merging:
# only applicable to unix users # only applicable to unix users
manualCommit: false manualCommit: false

View File

@ -62,7 +62,7 @@ func (self *CommitCommands) CommitCmdObj(message string) oscommands.ICmdObj {
// runs git commit without the -m argument meaning it will invoke the user's editor // runs git commit without the -m argument meaning it will invoke the user's editor
func (self *CommitCommands) CommitEditorCmdObj() oscommands.ICmdObj { func (self *CommitCommands) CommitEditorCmdObj() oscommands.ICmdObj {
return self.cmd.New(fmt.Sprintf("git commit%s", self.signoffFlag())) return self.cmd.New(fmt.Sprintf("git commit%s%s", self.signoffFlag(), self.verboseFlag()))
} }
func (self *CommitCommands) signoffFlag() string { func (self *CommitCommands) signoffFlag() string {
@ -73,6 +73,14 @@ func (self *CommitCommands) signoffFlag() string {
} }
} }
func (self *CommitCommands) verboseFlag() string {
if self.UserConfig.Git.Commit.Verbose {
return " --verbose"
} else {
return ""
}
}
// Get the subject of the HEAD commit // Get the subject of the HEAD commit
func (self *CommitCommands) GetHeadCommitMessage() (string, error) { func (self *CommitCommands) GetHeadCommitMessage() (string, error) {
message, err := self.cmd.New("git log -1 --pretty=%s").DontLog().RunWithOutput() message, err := self.cmd.New("git log -1 --pretty=%s").DontLog().RunWithOutput()

View File

@ -32,6 +32,7 @@ func TestCommitCommitObj(t *testing.T) {
testName string testName string
message string message string
configSignoff bool configSignoff bool
configVerbose bool
configSkipHookPrefix string configSkipHookPrefix string
expected string expected string
} }
@ -41,6 +42,7 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit", testName: "Commit",
message: "test", message: "test",
configSignoff: false, configSignoff: false,
configVerbose: false,
configSkipHookPrefix: "", configSkipHookPrefix: "",
expected: `git commit -m "test"`, expected: `git commit -m "test"`,
}, },
@ -48,6 +50,7 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit with --no-verify flag", testName: "Commit with --no-verify flag",
message: "WIP: test", message: "WIP: test",
configSignoff: false, configSignoff: false,
configVerbose: false,
configSkipHookPrefix: "WIP", configSkipHookPrefix: "WIP",
expected: `git commit --no-verify -m "WIP: test"`, expected: `git commit --no-verify -m "WIP: test"`,
}, },
@ -55,6 +58,7 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit with multiline message", testName: "Commit with multiline message",
message: "line1\nline2", message: "line1\nline2",
configSignoff: false, configSignoff: false,
configVerbose: false,
configSkipHookPrefix: "", configSkipHookPrefix: "",
expected: `git commit -m "line1" -m "line2"`, expected: `git commit -m "line1" -m "line2"`,
}, },
@ -62,13 +66,23 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit with signoff", testName: "Commit with signoff",
message: "test", message: "test",
configSignoff: true, configSignoff: true,
configVerbose: false,
configSkipHookPrefix: "", configSkipHookPrefix: "",
expected: `git commit --signoff -m "test"`, expected: `git commit --signoff -m "test"`,
}, },
{
testName: "Commit with message ignores verbose flag",
message: "test",
configSignoff: false,
configVerbose: true,
configSkipHookPrefix: "",
expected: `git commit -m "test"`,
},
{ {
testName: "Commit with signoff and no-verify", testName: "Commit with signoff and no-verify",
message: "WIP: test", message: "WIP: test",
configSignoff: true, configSignoff: true,
configVerbose: false,
configSkipHookPrefix: "WIP", configSkipHookPrefix: "WIP",
expected: `git commit --no-verify --signoff -m "WIP: test"`, expected: `git commit --no-verify --signoff -m "WIP: test"`,
}, },
@ -79,6 +93,7 @@ func TestCommitCommitObj(t *testing.T) {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
userConfig := config.GetDefaultConfig() userConfig := config.GetDefaultConfig()
userConfig.Git.Commit.SignOff = s.configSignoff userConfig.Git.Commit.SignOff = s.configSignoff
userConfig.Git.Commit.Verbose = s.configVerbose
userConfig.Git.SkipHookPrefix = s.configSkipHookPrefix userConfig.Git.SkipHookPrefix = s.configSkipHookPrefix
instance := buildCommitCommands(commonDeps{userConfig: userConfig}) instance := buildCommitCommands(commonDeps{userConfig: userConfig})

View File

@ -94,6 +94,7 @@ type PagingConfig struct {
type CommitConfig struct { type CommitConfig struct {
SignOff bool `yaml:"signOff"` SignOff bool `yaml:"signOff"`
Verbose bool `yaml:"verbose"`
} }
type MergingConfig struct { type MergingConfig struct {
@ -386,6 +387,7 @@ func GetDefaultConfig() *UserConfig {
}, },
Commit: CommitConfig{ Commit: CommitConfig{
SignOff: false, SignOff: false,
Verbose: false,
}, },
Merging: MergingConfig{ Merging: MergingConfig{
ManualCommit: false, ManualCommit: false,