submodule: remove gitmodules_config
[git/debian.git] / t / helper / test-submodule-config.c
blobf23db3b19a9911b554ca8eaf567cd0370d42af6e
1 #include "cache.h"
2 #include "config.h"
3 #include "submodule-config.h"
4 #include "submodule.h"
6 static void die_usage(int argc, const char **argv, const char *msg)
8 fprintf(stderr, "%s\n", msg);
9 fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
10 exit(1);
13 int cmd_main(int argc, const char **argv)
15 const char **arg = argv;
16 int my_argc = argc;
17 int output_url = 0;
18 int lookup_name = 0;
20 arg++;
21 my_argc--;
22 while (arg[0] && starts_with(arg[0], "--")) {
23 if (!strcmp(arg[0], "--url"))
24 output_url = 1;
25 if (!strcmp(arg[0], "--name"))
26 lookup_name = 1;
27 arg++;
28 my_argc--;
31 if (my_argc % 2 != 0)
32 die_usage(argc, argv, "Wrong number of arguments.");
34 setup_git_directory();
36 while (*arg) {
37 struct object_id commit_oid;
38 const struct submodule *submodule;
39 const char *commit;
40 const char *path_or_name;
42 commit = arg[0];
43 path_or_name = arg[1];
45 if (commit[0] == '\0')
46 oidclr(&commit_oid);
47 else if (get_oid(commit, &commit_oid) < 0)
48 die_usage(argc, argv, "Commit not found.");
50 if (lookup_name) {
51 submodule = submodule_from_name(&commit_oid, path_or_name);
52 } else
53 submodule = submodule_from_path(&commit_oid, path_or_name);
54 if (!submodule)
55 die_usage(argc, argv, "Submodule not found.");
57 if (output_url)
58 printf("Submodule url: '%s' for path '%s'\n",
59 submodule->url, submodule->path);
60 else
61 printf("Submodule name: '%s' for path '%s'\n",
62 submodule->name, submodule->path);
64 arg += 2;
67 submodule_free();
69 return 0;