@@ -118,6 +118,55 @@ static int module_name(int argc, const char **argv, const char *prefix)
118
118
119
119
return 0 ;
120
120
}
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
+
121
170
static int clone_submodule (const char * path , const char * gitdir , const char * url ,
122
171
const char * depth , const char * reference , int quiet )
123
172
{
@@ -139,7 +188,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
139
188
argv_array_push (& cp .args , path );
140
189
141
190
cp .git_cmd = 1 ;
142
- cp .env = local_repo_env ;
191
+ prepare_submodule_repo_env ( & cp .env_array ) ;
143
192
cp .no_stdin = 1 ;
144
193
145
194
return run_command (& cp );
@@ -180,14 +229,18 @@ static int module_clone(int argc, const char **argv, const char *prefix)
180
229
181
230
const char * const git_submodule_helper_usage [] = {
182
231
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>" ),
185
234
NULL
186
235
};
187
236
188
237
argc = parse_options (argc , argv , prefix , module_clone_options ,
189
238
git_submodule_helper_usage , 0 );
190
239
240
+ if (argc || !url || !path )
241
+ usage_with_options (git_submodule_helper_usage ,
242
+ module_clone_options );
243
+
191
244
strbuf_addf (& sb , "%s/modules/%s" , get_git_dir (), name );
192
245
sm_gitdir = strbuf_detach (& sb , NULL );
193
246
@@ -249,6 +302,22 @@ static int module_clone(int argc, const char **argv, const char *prefix)
249
302
return 0 ;
250
303
}
251
304
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
+
252
321
struct cmd_struct {
253
322
const char * cmd ;
254
323
int (* fn )(int , const char * * , const char * );
@@ -258,6 +327,7 @@ static struct cmd_struct commands[] = {
258
327
{"list" , module_list },
259
328
{"name" , module_name },
260
329
{"clone" , module_clone },
330
+ {"sanitize-config" , module_sanitize_config },
261
331
};
262
332
263
333
int cmd_submodule__helper (int argc , const char * * argv , const char * prefix )
0 commit comments