Skip to content

Commit

Permalink
feat(config): change git.commit.verbose to accept "default"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryooooooga committed Jan 6, 2023
1 parent 1cf24a0 commit 965f7bf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
}
Expand Down
73 changes: 57 additions & 16 deletions pkg/commands/git_commands/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -42,47 +41,34 @@ func TestCommitCommitObj(t *testing.T) {
testName: "Commit",
message: "test",
configSignoff: false,
configVerbose: false,
configSkipHookPrefix: "",
expected: `git commit -m "test"`,
},
{
testName: "Commit with --no-verify flag",
message: "WIP: test",
configSignoff: false,
configVerbose: false,
configSkipHookPrefix: "WIP",
expected: `git commit --no-verify -m "WIP: test"`,
},
{
testName: "Commit with multiline message",
message: "line1\nline2",
configSignoff: false,
configVerbose: false,
configSkipHookPrefix: "",
expected: `git commit -m "line1" -m "line2"`,
},
{
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"`,
},
Expand All @@ -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})
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -387,7 +387,7 @@ func GetDefaultConfig() *UserConfig {
},
Commit: CommitConfig{
SignOff: false,
Verbose: false,
Verbose: "default",
},
Merging: MergingConfig{
ManualCommit: false,
Expand Down

0 comments on commit 965f7bf

Please sign in to comment.