@@ -118,6 +118,55 @@ static int module_name(int argc, const char **argv, const char *prefix)
118118
119119 return 0 ;
120120}
121+
122+ /*
123+ * Rules to sanitize configuration variables that are Ok to be passed into
124+ * submodule operations from the parent project using "-c". Should only
125+ * include keys which are both (a) safe and (b) necessary for proper
126+ * operation.
127+ */
128+ static int submodule_config_ok (const char * var )
129+ {
130+ if (starts_with (var , "credential." ))
131+ return 1 ;
132+ return 0 ;
133+ }
134+
135+ static int sanitize_submodule_config (const char * var , const char * value , void * data )
136+ {
137+ struct strbuf * out = data ;
138+
139+ if (submodule_config_ok (var )) {
140+ if (out -> len )
141+ strbuf_addch (out , ' ' );
142+
143+ if (value )
144+ sq_quotef (out , "%s=%s" , var , value );
145+ else
146+ sq_quote_buf (out , var );
147+ }
148+
149+ return 0 ;
150+ }
151+
152+ static void prepare_submodule_repo_env (struct argv_array * out )
153+ {
154+ const char * const * var ;
155+
156+ for (var = local_repo_env ; * var ; var ++ ) {
157+ if (!strcmp (* var , CONFIG_DATA_ENVIRONMENT )) {
158+ struct strbuf sanitized_config = STRBUF_INIT ;
159+ git_config_from_parameters (sanitize_submodule_config ,
160+ & sanitized_config );
161+ argv_array_pushf (out , "%s=%s" , * var , sanitized_config .buf );
162+ strbuf_release (& sanitized_config );
163+ } else {
164+ argv_array_push (out , * var );
165+ }
166+ }
167+
168+ }
169+
121170static int clone_submodule (const char * path , const char * gitdir , const char * url ,
122171 const char * depth , const char * reference , int quiet )
123172{
@@ -139,7 +188,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
139188 argv_array_push (& cp .args , path );
140189
141190 cp .git_cmd = 1 ;
142- cp .env = local_repo_env ;
191+ prepare_submodule_repo_env ( & cp .env_array ) ;
143192 cp .no_stdin = 1 ;
144193
145194 return run_command (& cp );
@@ -180,14 +229,18 @@ static int module_clone(int argc, const char **argv, const char *prefix)
180229
181230 const char * const git_submodule_helper_usage [] = {
182231 N_ ("git submodule--helper clone [--prefix=<path>] [--quiet] "
183- "[--reference <repository>] [--name <name>] [--url <url>] "
184- "[--depth <depth>] [--] [ <path>...] " ),
232+ "[--reference <repository>] [--name <name>] [--depth <depth>] "
233+ "--url <url> --path <path>" ),
185234 NULL
186235 };
187236
188237 argc = parse_options (argc , argv , prefix , module_clone_options ,
189238 git_submodule_helper_usage , 0 );
190239
240+ if (argc || !url || !path )
241+ usage_with_options (git_submodule_helper_usage ,
242+ module_clone_options );
243+
191244 strbuf_addf (& sb , "%s/modules/%s" , get_git_dir (), name );
192245 sm_gitdir = strbuf_detach (& sb , NULL );
193246
@@ -249,6 +302,22 @@ static int module_clone(int argc, const char **argv, const char *prefix)
249302 return 0 ;
250303}
251304
305+ static int module_sanitize_config (int argc , const char * * argv , const char * prefix )
306+ {
307+ struct strbuf sanitized_config = STRBUF_INIT ;
308+
309+ if (argc > 1 )
310+ usage (_ ("git submodule--helper sanitize-config" ));
311+
312+ git_config_from_parameters (sanitize_submodule_config , & sanitized_config );
313+ if (sanitized_config .len )
314+ printf ("%s\n" , sanitized_config .buf );
315+
316+ strbuf_release (& sanitized_config );
317+
318+ return 0 ;
319+ }
320+
252321struct submodule_update_clone {
253322 /* index into 'list', the list of submodules to look into for cloning */
254323 int current ;
@@ -509,6 +578,7 @@ static struct cmd_struct commands[] = {
509578 {"list" , module_list },
510579 {"name" , module_name },
511580 {"clone" , module_clone },
581+ {"sanitize-config" , module_sanitize_config },
512582 {"update-clone" , update_clone }
513583};
514584
0 commit comments