Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Git Commit flags:
override author for commit
--date string
override date for commit
--git-flag strings
git flags, e.g. --git-flag="--branch"
-n, --no-verify
bypass pre-commit and commit-msg hooks.
-q, --quiet
suppress summary after successful commit
-s, --signoff
Expand All @@ -59,6 +63,8 @@ Commitizen flags:
Use "commitizen [command] --help" for more information about a command.
```

> To use more Git flags, you can use the '--git-flag' flag. Please do not conflict with other Git commit flags.

Commit with commitizen:

```
Expand Down
5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const (
FieldKeyTemplateSelect = "template-select"
)

// Config represents a configuration object.
type Config struct {
defaultTmpl *templates.Template
more []*templates.Template
}

// New creates a new Config object.
func New() *Config {
return &Config{}
}
Expand Down Expand Up @@ -154,6 +156,7 @@ func (c *Config) createTemplatesSelect(label string) *huh.Form {
)
}

// LoadTemplates reads a list of templates from the provided file.
func LoadTemplates(file string) ([]*templates.Template, error) {
if len(file) == 0 {
return nil, nil
Expand All @@ -166,10 +169,12 @@ func LoadTemplates(file string) ([]*templates.Template, error) {
return load(fd)
}

// Load reads a list of templates from the provided byte slice.
func Load(data []byte) ([]*templates.Template, error) {
return load(bytes.NewReader(data))
}

// load reads a list of templates from the provided io.Reader.
func load(reader io.Reader) ([]*templates.Template, error) {
var tmpls []*templates.Template
d := yaml.NewDecoder(reader)
Expand Down
1 change: 1 addition & 0 deletions internal/config/default.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package config

// DefaultCommitTemplate is the default commit template.
const DefaultCommitTemplate = `---
name: default
default: true
Expand Down
65 changes: 48 additions & 17 deletions internal/git/options.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
package git

import "github.com/spf13/pflag"
import (
"strings"

"github.com/spf13/pflag"
)

type Options struct {
Quiet bool
Verbose bool
SignOff bool
All bool
Amend bool
DryRun bool
Author string
Date string
Quiet bool
Verbose bool
SignOff bool
All bool
Amend bool
DryRun bool
NoVerify bool
Author string
Date string
ExtraGitFlags []string
}

func NewOptions() *Options {
return &Options{
Quiet: false,
Verbose: false,
SignOff: false,
All: false,
Amend: false,
DryRun: false,
Author: "",
Date: "",
Quiet: false,
Verbose: false,
SignOff: false,
All: false,
Amend: false,
NoVerify: false,
DryRun: false,
Author: "",
Date: "",
ExtraGitFlags: []string{},
}
}

Expand All @@ -35,6 +43,8 @@ func (o *Options) AddFlags(f *pflag.FlagSet) {
f.BoolVarP(&o.All, "all", "a", o.All, "commit all changed files.")
f.BoolVarP(&o.SignOff, "signoff", "s", o.SignOff, "add a Signed-off-by trailer.")
f.BoolVar(&o.Amend, "amend", o.Amend, "amend previous commit")
f.BoolVarP(&o.NoVerify, "no-verify", "n", o.NoVerify, "bypass pre-commit and commit-msg hooks.")
f.StringSliceVar(&o.ExtraGitFlags, "git-flag", o.ExtraGitFlags, "git flags, e.g. --git-flag=\"--branch\"")
}

func (o *Options) Combine(filename string) []string {
Expand All @@ -61,9 +71,30 @@ func (o *Options) Combine(filename string) []string {
if o.Amend {
combination = append(combination, "--amend")
}
if o.NoVerify {
combination = append(combination, "--no-verify")
}
if o.DryRun {
combination = append(combination, "--dry-run")
}
if len(o.ExtraGitFlags) > 0 {
result := deDuplicateFlag(o.ExtraGitFlags, "-F", "--file")
combination = append(combination, result...)
}

return combination
}

func deDuplicateFlag(sli []string, short, long string) []string {
var result []string
for _, s := range sli {
if strings.HasPrefix(s, short) {
continue
}
if strings.HasPrefix(s, long) {
continue
}
result = append(result, s)
}
return result
}
Loading