4 #include "parse-options.h"
6 #include "repository.h"
7 #include "run-command.h"
8 #include "string-list.h"
10 static const char * const for_each_repo_usage
[] = {
11 N_("git for-each-repo --config=<config> [--] <arguments>"),
15 static int run_command_on_repo(const char *path
, int argc
, const char ** argv
)
18 struct child_process child
= CHILD_PROCESS_INIT
;
19 char *abspath
= interpolate_path(path
, 0);
22 strvec_pushl(&child
.args
, "-C", abspath
, NULL
);
24 for (i
= 0; i
< argc
; i
++)
25 strvec_push(&child
.args
, argv
[i
]);
29 return run_command(&child
);
32 int cmd_for_each_repo(int argc
, const char **argv
, const char *prefix
)
34 static const char *config_key
= NULL
;
36 const struct string_list
*values
;
39 const struct option options
[] = {
40 OPT_STRING(0, "config", &config_key
, N_("config"),
41 N_("config key storing a list of repository paths")),
45 argc
= parse_options(argc
, argv
, prefix
, options
, for_each_repo_usage
,
46 PARSE_OPT_STOP_AT_NON_OPTION
);
49 die(_("missing --config=<config>"));
51 err
= repo_config_get_string_multi(the_repository
, config_key
, &values
);
53 usage_msg_optf(_("got bad config --config=%s"),
54 for_each_repo_usage
, options
, config_key
);
58 for (i
= 0; !result
&& i
< values
->nr
; i
++)
59 result
= run_command_on_repo(values
->items
[i
].string
, argc
, argv
);