11package git
22
3- import "github.com/spf13/pflag"
3+ import (
4+ "strings"
5+
6+ "github.com/spf13/pflag"
7+ )
48
59type Options struct {
6- Quiet bool
7- Verbose bool
8- SignOff bool
9- All bool
10- Amend bool
11- DryRun bool
12- Author string
13- Date string
10+ Quiet bool
11+ Verbose bool
12+ SignOff bool
13+ All bool
14+ Amend bool
15+ DryRun bool
16+ NoVerify bool
17+ Author string
18+ Date string
19+ ExtraGitFlags []string
1420}
1521
1622func NewOptions () * Options {
1723 return & Options {
18- Quiet : false ,
19- Verbose : false ,
20- SignOff : false ,
21- All : false ,
22- Amend : false ,
23- DryRun : false ,
24- Author : "" ,
25- Date : "" ,
24+ Quiet : false ,
25+ Verbose : false ,
26+ SignOff : false ,
27+ All : false ,
28+ Amend : false ,
29+ NoVerify : false ,
30+ DryRun : false ,
31+ Author : "" ,
32+ Date : "" ,
33+ ExtraGitFlags : []string {},
2634 }
2735}
2836
@@ -35,6 +43,8 @@ func (o *Options) AddFlags(f *pflag.FlagSet) {
3543 f .BoolVarP (& o .All , "all" , "a" , o .All , "commit all changed files." )
3644 f .BoolVarP (& o .SignOff , "signoff" , "s" , o .SignOff , "add a Signed-off-by trailer." )
3745 f .BoolVar (& o .Amend , "amend" , o .Amend , "amend previous commit" )
46+ f .BoolVarP (& o .NoVerify , "no-verify" , "n" , o .NoVerify , "bypass pre-commit and commit-msg hooks." )
47+ f .StringSliceVar (& o .ExtraGitFlags , "git-flag" , o .ExtraGitFlags , "git flags, e.g. --git-flag=\" --branch\" " )
3848}
3949
4050func (o * Options ) Combine (filename string ) []string {
@@ -61,9 +71,30 @@ func (o *Options) Combine(filename string) []string {
6171 if o .Amend {
6272 combination = append (combination , "--amend" )
6373 }
74+ if o .NoVerify {
75+ combination = append (combination , "--no-verify" )
76+ }
6477 if o .DryRun {
6578 combination = append (combination , "--dry-run" )
6679 }
80+ if len (o .ExtraGitFlags ) > 0 {
81+ result := deDuplicateFlag (o .ExtraGitFlags , "-F" , "--file" )
82+ combination = append (combination , result ... )
83+ }
6784
6885 return combination
6986}
87+
88+ func deDuplicateFlag (sli []string , short , long string ) []string {
89+ var result []string
90+ for _ , s := range sli {
91+ if strings .HasPrefix (s , short ) {
92+ continue
93+ }
94+ if strings .HasPrefix (s , long ) {
95+ continue
96+ }
97+ result = append (result , s )
98+ }
99+ return result
100+ }
0 commit comments