summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-01-17 09:19:22 +1100
committerGitHub <noreply@github.com>2023-01-17 09:19:22 +1100
commitfd86d294002e70bc2c65c12b356cf75a1cde2be5 (patch)
treef2979e814b87be6cbd62abbe54d55a22833e9884
parent6127e487dd977dc4a5c5f12fc72cc70d9d6205d1 (diff)
parent21f8857d360dcc1c9079616c726e9b708a66726e (diff)
Merge pull request #2343 from Ryooooooga/commit-verbose
-rw-r--r--docs/Config.md2
-rw-r--r--pkg/commands/git_commands/commit.go7
-rw-r--r--pkg/commands/git_commands/commit_loader.go12
-rw-r--r--pkg/commands/git_commands/commit_test.go73
-rw-r--r--pkg/config/user_config.go6
5 files changed, 67 insertions, 33 deletions
diff --git a/docs/Config.md b/docs/Config.md
index eaf131865..e30bf6786 100644
--- a/docs/Config.md
+++ b/docs/Config.md
@@ -67,7 +67,7 @@ git:
useConfig: false
commit:
signOff: false
- verbose: false
+ verbose: default # one of 'default' | 'always' | 'never'
merging:
# only applicable to unix users
manualCommit: false
diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go
index be06cb245..b5293a2ff 100644
--- a/pkg/commands/git_commands/commit.go
+++ b/pkg/commands/git_commands/commit.go
@@ -74,9 +74,12 @@ func (self *CommitCommands) signoffFlag() string {
}
func (self *CommitCommands) verboseFlag() string {
- if self.UserConfig.Git.Commit.Verbose {
+ switch self.config.UserConfig.Git.Commit.Verbose {
+ case "always":
return " --verbose"
- } else {
+ case "never":
+ return " --no-verbose"
+ default:
return ""
}
}
diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go
index f89f62c48..401292875 100644
--- a/pkg/commands/git_commands/commit_loader.go
+++ b/pkg/commands/git_commands/commit_loader.go
@@ -446,14 +446,4 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) oscommands.ICmdObj {
).DontLog()
}
-var prettyFormat = fmt.Sprintf(
- "--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"
+const prettyFormat = `--pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s"`
diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go
index f44d350f9..1d6bc7f8f 100644
--- a/pkg/commands/git_commands/commit_test.go
+++ b/pkg/commands/git_commands/commit_test.go
@@ -27,12 +27,11 @@ func TestCommitResetToCommit(t *testing.T) {
runner.CheckForMissingCalls()
}
-func TestCommitCommitObj(t *testing.T) {
+func TestCommitCommitCmdObj(t *testing.T) {
type scenario struct {
testName string
message string
configSignoff bool
- configVerbose bool
configSkipHookPrefix string
expected string
}
@@ -42,7 +41,6 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit",
message: "test",
configSignoff: false,
- configVerbose: false,
configSkipHookPrefix: "",
expected: `git commit -m "test"`,
},
@@ -50,7 +48,6 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit with --no-verify flag",
message: "WIP: test",
configSignoff: false,
- configVerbose: false,
configSkipHookPrefix: "WIP",
expected: `git commit --no-verify -m "WIP: test"`,
},
@@ -58,7 +55,6 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit with multiline message",
message: "line1\nline2",
configSignoff: false,
- configVerbose: false,
configSkipHookPrefix: "",
expected: `git commit -m "line1" -m "line2"`,
},
@@ -66,23 +62,13 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit with signoff",
message: "test",
configSignoff: true,
- configVerbose: false,
configSkipHookPrefix: "",
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",
message: "WIP: test",
configSignoff: true,
- configVerbose: false,
configSkipHookPrefix: "WIP",
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) {
userConfig := config.GetDefaultConfig()
userConfig.Git.Commit.SignOff = s.configSignoff
- userConfig.Git.Commit.Verbose = s.configVerbose
userConfig.Git.SkipHookPrefix = s.configSkipHookPrefix
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) {
type scenario struct {
testName string
diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go
index 06dcf085b..59244f3f4 100644
--- a/pkg/config/user_config.go
+++ b/pkg/config/user_config.go
@@ -93,8 +93,8 @@ type PagingConfig struct {
}
type CommitConfig struct {
- SignOff bool `yaml:"signOff"`
- Verbose bool `yaml:"verbose"`
+ SignOff bool `yaml:"signOff"`
+ Verbose string `yaml:"verbose"`
}
type MergingConfig struct {
@@ -387,7 +387,7 @@ func GetDefaultConfig() *UserConfig {
},
Commit: CommitConfig{
SignOff: false,
- Verbose: false,
+ Verbose: "default",
},
Merging: MergingConfig{
ManualCommit: false,