Coverage Report

Created: 2024-09-08 06:23

/src/git/builtin/for-each-repo.c
Line
Count
Source (jump to first uncovered line)
1
#include "builtin.h"
2
#include "config.h"
3
#include "gettext.h"
4
#include "parse-options.h"
5
#include "path.h"
6
#include "repository.h"
7
#include "run-command.h"
8
#include "string-list.h"
9
10
static const char * const for_each_repo_usage[] = {
11
  N_("git for-each-repo --config=<config> [--] <arguments>"),
12
  NULL
13
};
14
15
static int run_command_on_repo(const char *path, int argc, const char ** argv)
16
0
{
17
0
  int i;
18
0
  struct child_process child = CHILD_PROCESS_INIT;
19
0
  char *abspath = interpolate_path(path, 0);
20
21
0
  child.git_cmd = 1;
22
0
  strvec_pushl(&child.args, "-C", abspath, NULL);
23
24
0
  for (i = 0; i < argc; i++)
25
0
    strvec_push(&child.args, argv[i]);
26
27
0
  free(abspath);
28
29
0
  return run_command(&child);
30
0
}
31
32
int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
33
0
{
34
0
  static const char *config_key = NULL;
35
0
  int keep_going = 0;
36
0
  int i, result = 0;
37
0
  const struct string_list *values;
38
0
  int err;
39
40
0
  const struct option options[] = {
41
0
    OPT_STRING(0, "config", &config_key, N_("config"),
42
0
         N_("config key storing a list of repository paths")),
43
0
    OPT_BOOL(0, "keep-going", &keep_going,
44
0
       N_("keep going even if command fails in a repository")),
45
0
    OPT_END()
46
0
  };
47
48
0
  argc = parse_options(argc, argv, prefix, options, for_each_repo_usage,
49
0
           PARSE_OPT_STOP_AT_NON_OPTION);
50
51
0
  if (!config_key)
52
0
    die(_("missing --config=<config>"));
53
54
0
  err = repo_config_get_string_multi(the_repository, config_key, &values);
55
0
  if (err < 0)
56
0
    usage_msg_optf(_("got bad config --config=%s"),
57
0
             for_each_repo_usage, options, config_key);
58
0
  else if (err)
59
0
    return 0;
60
61
0
  for (i = 0; i < values->nr; i++) {
62
0
    int ret = run_command_on_repo(values->items[i].string, argc, argv);
63
0
    if (ret) {
64
0
      if (!keep_going)
65
0
          return ret;
66
0
      result = 1;
67
0
    }
68
0
  }
69
70
0
  return result;
71
0
}