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