push: test that --recurse-submodules on command line overrides config
[git.git] / test-submodule-config.c
blobdab8c27768160d4cfa61c41a95004eb7a8a336b6
1 #include "cache.h"
2 #include "submodule-config.h"
3 #include "submodule.h"
5 static void die_usage(int argc, char **argv, const char *msg)
7 fprintf(stderr, "%s\n", msg);
8 fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
9 exit(1);
12 static int git_test_config(const char *var, const char *value, void *cb)
14 return parse_submodule_config_option(var, value);
17 int main(int argc, char **argv)
19 char **arg = argv;
20 int my_argc = argc;
21 int output_url = 0;
22 int lookup_name = 0;
24 arg++;
25 my_argc--;
26 while (starts_with(arg[0], "--")) {
27 if (!strcmp(arg[0], "--url"))
28 output_url = 1;
29 if (!strcmp(arg[0], "--name"))
30 lookup_name = 1;
31 arg++;
32 my_argc--;
35 if (my_argc % 2 != 0)
36 die_usage(argc, argv, "Wrong number of arguments.");
38 setup_git_directory();
39 gitmodules_config();
40 git_config(git_test_config, NULL);
42 while (*arg) {
43 unsigned char commit_sha1[20];
44 const struct submodule *submodule;
45 const char *commit;
46 const char *path_or_name;
48 commit = arg[0];
49 path_or_name = arg[1];
51 if (commit[0] == '\0')
52 hashcpy(commit_sha1, null_sha1);
53 else if (get_sha1(commit, commit_sha1) < 0)
54 die_usage(argc, argv, "Commit not found.");
56 if (lookup_name) {
57 submodule = submodule_from_name(commit_sha1, path_or_name);
58 } else
59 submodule = submodule_from_path(commit_sha1, path_or_name);
60 if (!submodule)
61 die_usage(argc, argv, "Submodule not found.");
63 if (output_url)
64 printf("Submodule url: '%s' for path '%s'\n",
65 submodule->url, submodule->path);
66 else
67 printf("Submodule name: '%s' for path '%s'\n",
68 submodule->name, submodule->path);
70 arg += 2;
73 submodule_free();
75 return 0;