@@ -297,9 +297,12 @@ func main() {
297297 flGitCmd := pflag .String ("git" ,
298298 envString ("git" , "GITSYNC_GIT" , "GIT_SYNC_GIT" ),
299299 "the git command to run (subject to PATH search, mostly for testing)" )
300- flGitConfig := pflag .String ("git-config" ,
300+ flGitConfigString := pflag .String ("git-config" ,
301301 envString ("" , "GITSYNC_GIT_CONFIG" , "GIT_SYNC_GIT_CONFIG" ),
302302 "additional git config options in 'section.var1:val1,\" section.sub.var2\" :\" val2\" ' format" )
303+ flGitConfigList := pflag .StringArray ("git-config-add" , // Array vs. Slice to avoid CSV parsing
304+ nil ,
305+ "add one additional git config option in 'section.var1:val1' format; can be repeated" )
303306 flGitGC := pflag .String ("git-gc" ,
304307 envString ("always" , "GITSYNC_GIT_GC" , "GIT_SYNC_GIT_GC" ),
305308 "git garbage collection behavior: one of 'auto', 'always', 'aggressive', or 'off'" )
@@ -786,9 +789,16 @@ func main() {
786789 }
787790
788791 // This needs to be after all other git-related config flags.
789- if * flGitConfig != "" {
790- if err := git .SetupExtraGitConfigs (ctx , * flGitConfig ); err != nil {
791- log .Error (err , "can't set additional git configs" , "configs" , * flGitConfig )
792+ if * flGitConfigString != "" {
793+ if err := git .SetupExtraGitConfigs (ctx , * flGitConfigString , "--git-config" ); err != nil {
794+ log .Error (err , "can't set additional git configs" , "configs" , * flGitConfigString )
795+ os .Exit (1 )
796+ }
797+ }
798+ if len (* flGitConfigList ) > 0 {
799+ str := strings .Join (* flGitConfigList , "," )
800+ if err := git .SetupExtraGitConfigs (ctx , str , "--git-config-add" ); err != nil {
801+ log .Error (err , "can't set additional git configs" , "configs" , str )
792802 os .Exit (1 )
793803 }
794804 }
@@ -2164,10 +2174,6 @@ func (git *repoSync) SetupDefaultGitConfigs(ctx context.Context) error {
21642174 // Never prompt for a password.
21652175 key : "core.askPass" ,
21662176 val : "true" ,
2167- }, {
2168- // Mark repos as safe (avoid a "dubious ownership" error).
2169- key : "safe.directory" ,
2170- val : "*" ,
21712177 }}
21722178
21732179 for _ , kv := range configs {
@@ -2180,10 +2186,10 @@ func (git *repoSync) SetupDefaultGitConfigs(ctx context.Context) error {
21802186
21812187// SetupExtraGitConfigs configures the global git environment with user-provided
21822188// override settings.
2183- func (git * repoSync ) SetupExtraGitConfigs (ctx context.Context , configsFlag string ) error {
2189+ func (git * repoSync ) SetupExtraGitConfigs (ctx context.Context , configsFlag string , flagName string ) error {
21842190 configs , err := parseGitConfigs (configsFlag )
21852191 if err != nil {
2186- return fmt .Errorf ("can't parse --git-config flag: %w" , err )
2192+ return fmt .Errorf ("can't parse %s flag: %w" , flagName , err )
21872193 }
21882194 git .log .V (1 ).Info ("setting additional git configs" , "configs" , configs )
21892195 for _ , kv := range configs {
@@ -2535,7 +2541,28 @@ OPTIONS
25352541 --git-config <string>, $GITSYNC_GIT_CONFIG
25362542 Additional git config options in a comma-separated 'key:val'
25372543 format. The parsed keys and values are passed to 'git config' and
2538- must be valid syntax for that command.
2544+ must be valid syntax for that command. This is similar to
2545+ --git-config-add, but uses a single comma-separated string.
2546+
2547+ Both keys and values can be either quoted or unquoted strings.
2548+ Within quoted keys and all values (quoted or not), the following
2549+ escape sequences are supported:
2550+ '\n' => [newline]
2551+ '\t' => [tab]
2552+ '\"' => '"'
2553+ '\,' => ','
2554+ '\\' => '\'
2555+ To include a colon within a key (e.g. a URL) the key must be
2556+ quoted. Within unquoted values commas must be escaped. Within
2557+ quoted values commas may be escaped, but are not required to be.
2558+ Any other escape sequence is an error.
2559+
2560+ --git-config-add <string>
2561+ Add one git config option. The parsed key and value are passed to
2562+ 'git config' and must be valid syntax for that command. This flag
2563+ can be specified more than once. This is similar to --git-config,
2564+ but allows multiple discrete uses of the flag instead of a single
2565+ comma-separated string.
25392566
25402567 Both keys and values can be either quoted or unquoted strings.
25412568 Within quoted keys and all values (quoted or not), the following
0 commit comments