Skip to content

Commit d5de0ac

Browse files
committed
fix(flags): "-F/--file" provided by the "--git-flag" should be ignored
1 parent b91b8bf commit d5de0ac

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

internal/git/options.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package git
22

33
import (
4+
"strings"
5+
46
"github.com/spf13/pflag"
57
)
68

@@ -76,8 +78,23 @@ func (o *Options) Combine(filename string) []string {
7678
combination = append(combination, "--dry-run")
7779
}
7880
if len(o.ExtraGitFlags) > 0 {
79-
combination = append(combination, o.ExtraGitFlags...)
81+
result := deDuplicateFlag(o.ExtraGitFlags, "-F", "--file")
82+
combination = append(combination, result...)
8083
}
8184

8285
return combination
83-
}
86+
}
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

Comments
 (0)