4 #include "parse-options.h"
5 #include "run-command.h"
6 #include "string-list.h"
8 static const char * const for_each_repo_usage
[] = {
9 N_("git for-each-repo --config=<config> <command-args>"),
13 static int run_command_on_repo(const char *path
, int argc
, const char ** argv
)
16 struct child_process child
= CHILD_PROCESS_INIT
;
19 strvec_pushl(&child
.args
, "-C", path
, NULL
);
21 for (i
= 0; i
< argc
; i
++)
22 strvec_push(&child
.args
, argv
[i
]);
24 return run_command(&child
);
27 int cmd_for_each_repo(int argc
, const char **argv
, const char *prefix
)
29 static const char *config_key
= NULL
;
31 const struct string_list
*values
;
33 const struct option options
[] = {
34 OPT_STRING(0, "config", &config_key
, N_("config"),
35 N_("config key storing a list of repository paths")),
39 argc
= parse_options(argc
, argv
, prefix
, options
, for_each_repo_usage
,
40 PARSE_OPT_STOP_AT_NON_OPTION
);
43 die(_("missing --config=<config>"));
45 values
= repo_config_get_value_multi(the_repository
,
49 * Do nothing on an empty list, which is equivalent to the case
50 * where the config variable does not exist at all.
55 for (i
= 0; !result
&& i
< values
->nr
; i
++)
56 result
= run_command_on_repo(values
->items
[i
].string
, argc
, argv
);