Merge branch 'en/header-split-cache-h-part-2'
[alt-git.git] / t / helper / test-submodule-config.c
blob9df2f03ac80de2b9cf977b0d7e252eb904c903f3
1 #include "test-tool.h"
2 #include "config.h"
3 #include "hash.h"
4 #include "object-name.h"
5 #include "repository.h"
6 #include "setup.h"
7 #include "submodule-config.h"
8 #include "submodule.h"
10 static void die_usage(int argc UNUSED, const char **argv, const char *msg)
12 fprintf(stderr, "%s\n", msg);
13 fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
14 exit(1);
17 int cmd__submodule_config(int argc, const char **argv)
19 const char **arg = argv;
20 int my_argc = argc;
21 int lookup_name = 0;
23 arg++;
24 my_argc--;
25 while (arg[0] && starts_with(arg[0], "--")) {
26 if (!strcmp(arg[0], "--name"))
27 lookup_name = 1;
28 arg++;
29 my_argc--;
32 if (my_argc % 2 != 0)
33 die_usage(argc, argv, "Wrong number of arguments.");
35 setup_git_directory();
37 while (*arg) {
38 struct object_id commit_oid;
39 const struct submodule *submodule;
40 const char *commit;
41 const char *path_or_name;
43 commit = arg[0];
44 path_or_name = arg[1];
46 if (commit[0] == '\0')
47 oidclr(&commit_oid);
48 else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
49 die_usage(argc, argv, "Commit not found.");
51 if (lookup_name) {
52 submodule = submodule_from_name(the_repository,
53 &commit_oid, path_or_name);
54 } else
55 submodule = submodule_from_path(the_repository,
56 &commit_oid, path_or_name);
57 if (!submodule)
58 die_usage(argc, argv, "Submodule not found.");
60 printf("Submodule name: '%s' for path '%s'\n", submodule->name,
61 submodule->path);
63 arg += 2;
66 submodule_free(the_repository);
68 return 0;