1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-19 12:12:42 +02:00

Merge pull request #2343 from Ryooooooga/commit-verbose

This commit is contained in:
Jesse Duffield 2023-01-17 09:19:22 +11:00 committed by GitHub
commit fd86d29400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 33 deletions

View File

@ -67,7 +67,7 @@ git:
useConfig: false useConfig: false
commit: commit:
signOff: false signOff: false
verbose: false verbose: default # one of 'default' | 'always' | 'never'
merging: merging:
# only applicable to unix users # only applicable to unix users
manualCommit: false manualCommit: false

View File

@ -74,9 +74,12 @@ func (self *CommitCommands) signoffFlag() string {
} }
func (self *CommitCommands) verboseFlag() string { func (self *CommitCommands) verboseFlag() string {
if self.UserConfig.Git.Commit.Verbose { switch self.config.UserConfig.Git.Commit.Verbose {
case "always":
return " --verbose" return " --verbose"
} else { case "never":
return " --no-verbose"
default:
return "" return ""
} }
} }

View File

@ -446,14 +446,4 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
).DontLog() ).DontLog()
} }
var prettyFormat = fmt.Sprintf( const prettyFormat = `--pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s"`
"--pretty=format:\"%%H%s%%at%s%%aN%s%%ae%s%%d%s%%p%s%%s\"",
NULL_CODE,
NULL_CODE,
NULL_CODE,
NULL_CODE,
NULL_CODE,
NULL_CODE,
)
const NULL_CODE = "%x00"

View File

@ -27,12 +27,11 @@ func TestCommitResetToCommit(t *testing.T) {
runner.CheckForMissingCalls() runner.CheckForMissingCalls()
} }
func TestCommitCommitObj(t *testing.T) { func TestCommitCommitCmdObj(t *testing.T) {
type scenario struct { type scenario struct {
testName string testName string
message string message string
configSignoff bool configSignoff bool
configVerbose bool
configSkipHookPrefix string configSkipHookPrefix string
expected string expected string
} }
@ -42,7 +41,6 @@ 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"`,
}, },
@ -50,7 +48,6 @@ 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"`,
}, },
@ -58,7 +55,6 @@ 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"`,
}, },
@ -66,23 +62,13 @@ 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"`,
}, },
@ -93,7 +79,6 @@ 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})
@ -104,6 +89,62 @@ func TestCommitCommitObj(t *testing.T) {
} }
} }
func TestCommitCommitEditorCmdObj(t *testing.T) {
type scenario struct {
testName string
configSignoff bool
configVerbose string
expected string
}
scenarios := []scenario{
{
testName: "Commit using editor",
configSignoff: false,
configVerbose: "default",
expected: `git commit`,
},
{
testName: "Commit with --no-verbose flag",
configSignoff: false,
configVerbose: "never",
expected: `git commit --no-verbose`,
},
{
testName: "Commit with --verbose flag",
configSignoff: false,
configVerbose: "always",
expected: `git commit --verbose`,
},
{
testName: "Commit with --signoff",
configSignoff: true,
configVerbose: "default",
expected: `git commit --signoff`,
},
{
testName: "Commit with --signoff and --no-verbose",
configSignoff: true,
configVerbose: "never",
expected: `git commit --signoff --no-verbose`,
},
}
for _, s := range scenarios {
s := s
t.Run(s.testName, func(t *testing.T) {
userConfig := config.GetDefaultConfig()
userConfig.Git.Commit.SignOff = s.configSignoff
userConfig.Git.Commit.Verbose = s.configVerbose
instance := buildCommitCommands(commonDeps{userConfig: userConfig})
cmdStr := instance.CommitEditorCmdObj().ToString()
assert.Equal(t, s.expected, cmdStr)
})
}
}
func TestCommitCreateFixupCommit(t *testing.T) { func TestCommitCreateFixupCommit(t *testing.T) {
type scenario struct { type scenario struct {
testName string testName string

View File

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