@@ -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 ("add-git-config" ,
304+ nil ,
305+ "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 ); 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 ); 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 {
@@ -2455,6 +2461,26 @@ OPTIONS
24552461 error while a misspelled environment variable is silently ignored. Some
24562462 options can only be specified as an environment variable.
24572463
2464+ --add-git-config <string>
2465+ Add one git config option. The parsed key and value are passed to
2466+ 'git config' and must be valid syntax for that command. This flag
2467+ can be specified more than once. This is similar to --git-config,
2468+ but allows multiple discrete uses of the flag instead of a single
2469+ comma-separated string.
2470+
2471+ Both keys and values can be either quoted or unquoted strings.
2472+ Within quoted keys and all values (quoted or not), the following
2473+ escape sequences are supported:
2474+ '\n' => [newline]
2475+ '\t' => [tab]
2476+ '\"' => '"'
2477+ '\,' => ','
2478+ '\\' => '\'
2479+ To include a colon within a key (e.g. a URL) the key must be
2480+ quoted. Within unquoted values commas must be escaped. Within
2481+ quoted values commas may be escaped, but are not required to be.
2482+ Any other escape sequence is an error.
2483+
24582484 --add-user, $GITSYNC_ADD_USER
24592485 Add a record to /etc/passwd for the current UID/GID. This is
24602486 needed to use SSH with an arbitrary UID. This assumes that
@@ -2535,7 +2561,8 @@ OPTIONS
25352561 --git-config <string>, $GITSYNC_GIT_CONFIG
25362562 Additional git config options in a comma-separated 'key:val'
25372563 format. The parsed keys and values are passed to 'git config' and
2538- must be valid syntax for that command.
2564+ must be valid syntax for that command. This is similar to
2565+ --add-git-config, but uses a single 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