Skip to content

Commit

Permalink
Merge pull request jesseduffield#2341 from knutwalker/commit-verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield authored Jan 1, 2023
2 parents c8fc1c3 + d98130c commit 1bb138c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ git:
useConfig: false
commit:
signOff: false
verbose: false
merging:
# only applicable to unix users
manualCommit: false
Expand Down
10 changes: 9 additions & 1 deletion pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 {
Expand All @@ -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
func (self *CommitCommands) GetHeadCommitMessage() (string, error) {
message, err := self.cmd.New("git log -1 --pretty=%s").DontLog().RunWithOutput()
Expand Down
15 changes: 15 additions & 0 deletions pkg/commands/git_commands/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestCommitCommitObj(t *testing.T) {
testName string
message string
configSignoff bool
configVerbose bool
configSkipHookPrefix string
expected string
}
Expand All @@ -41,34 +42,47 @@ 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 @@ -79,6 +93,7 @@ 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 Down
2 changes: 2 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type PagingConfig struct {

type CommitConfig struct {
SignOff bool `yaml:"signOff"`
Verbose bool `yaml:"verbose"`
}

type MergingConfig struct {
Expand Down Expand Up @@ -386,6 +387,7 @@ func GetDefaultConfig() *UserConfig {
},
Commit: CommitConfig{
SignOff: false,
Verbose: false,
},
Merging: MergingConfig{
ManualCommit: false,
Expand Down

0 comments on commit 1bb138c

Please sign in to comment.