2 #include "submodule-config.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]);
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)
26 while (starts_with(arg[0], "--")) {
27 if (!strcmp(arg[0], "--url"))
29 if (!strcmp(arg[0], "--name"))
36 die_usage(argc, argv, "Wrong number of arguments.");
38 setup_git_directory();
40 git_config(git_test_config, NULL);
43 unsigned char commit_sha1[20];
44 const struct submodule *submodule;
46 const char *path_or_name;
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.");
57 submodule = submodule_from_name(commit_sha1, path_or_name);
59 submodule = submodule_from_path(commit_sha1, path_or_name);
61 die_usage(argc, argv, "Submodule not found.");
64 printf("Submodule url: '%s' for path '%s'\n",
65 submodule->url, submodule->path);
67 printf("Submodule name: '%s' for path '%s'\n",
68 submodule->name, submodule->path);