@@ -17,6 +17,25 @@ const (
1717 GitBinary = "git"
1818)
1919
20+ type GitConfig struct {
21+ Url string
22+ Section string
23+ Key string
24+ Value string
25+ }
26+
27+ func (c * GitConfig ) Name () string {
28+ return fmt .Sprintf ("%s.%s.%s" , c .Section , c .Url , c .Key )
29+ }
30+
31+ func (c * GitConfig ) ArgsGlobal () []string {
32+ return []string {"config" , "--global" , c .Name (), c .Value }
33+ }
34+
35+ func (c * GitConfig ) CommandSuggestGlobal () string {
36+ return fmt .Sprintf ("git %s" , strings .Join (c .ArgsGlobal (), " " ))
37+ }
38+
2039// ConfigGetURLMatch call 'git config --get-urlmatch' underneath
2140func ConfigGetURLMatch (key , url string ) string {
2241 var stdout bytes.Buffer
@@ -32,16 +51,23 @@ func ConfigGetURLMatch(key, url string) string {
3251 return strings .TrimSpace (string (stdout .Bytes ()))
3352}
3453
54+ // SetConfigGlobal is a new signature for SetGlobalConfig
55+ func SetConfigGlobal (config * GitConfig ) {
56+ cmd := exec .Command (GitBinary , config .ArgsGlobal ()... )
57+ if err := cmd .Run (); err != nil {
58+ log .Fatal ().Msgf ("SetGlobalConfig - could not set config '%s': %s" , config .Name (), err )
59+ }
60+ }
61+
3562// SetGlobalConfig allows to set system-wide Git configuration.
3663// The application exits in case of error.
3764func SetGlobalConfig (url , section , key , value string ) {
38- x := fmt .Sprintf ("%s.%s.%s" , section , url , key )
39- args := []string {"config" , "--global" , x , value }
40- cmd := exec .Command (GitBinary , args ... )
41-
42- if err := cmd .Run (); err != nil {
43- log .Fatal ().Msgf ("SetGlobalConfig - could not set config '%s': %s" , x , err )
44- }
65+ SetConfigGlobal (& GitConfig {
66+ Url : url ,
67+ Section : section ,
68+ Key : key ,
69+ Value : value ,
70+ })
4571}
4672
4773// PassThruRemoteHTTPSHelper exec the git-remote-https helper,
0 commit comments