]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-submodule-config.c
object-name.h: move declarations for object-name.c functions from cache.h
[thirdparty/git.git] / t / helper / test-submodule-config.c
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "config.h"
4 #include "object-name.h"
5 #include "setup.h"
6 #include "submodule-config.h"
7 #include "submodule.h"
8
9 static void die_usage(int argc, const char **argv, const char *msg)
10 {
11 fprintf(stderr, "%s\n", msg);
12 fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
13 exit(1);
14 }
15
16 int cmd__submodule_config(int argc, const char **argv)
17 {
18 const char **arg = argv;
19 int my_argc = argc;
20 int lookup_name = 0;
21
22 arg++;
23 my_argc--;
24 while (arg[0] && starts_with(arg[0], "--")) {
25 if (!strcmp(arg[0], "--name"))
26 lookup_name = 1;
27 arg++;
28 my_argc--;
29 }
30
31 if (my_argc % 2 != 0)
32 die_usage(argc, argv, "Wrong number of arguments.");
33
34 setup_git_directory();
35
36 while (*arg) {
37 struct object_id commit_oid;
38 const struct submodule *submodule;
39 const char *commit;
40 const char *path_or_name;
41
42 commit = arg[0];
43 path_or_name = arg[1];
44
45 if (commit[0] == '\0')
46 oidclr(&commit_oid);
47 else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
48 die_usage(argc, argv, "Commit not found.");
49
50 if (lookup_name) {
51 submodule = submodule_from_name(the_repository,
52 &commit_oid, path_or_name);
53 } else
54 submodule = submodule_from_path(the_repository,
55 &commit_oid, path_or_name);
56 if (!submodule)
57 die_usage(argc, argv, "Submodule not found.");
58
59 printf("Submodule name: '%s' for path '%s'\n", submodule->name,
60 submodule->path);
61
62 arg += 2;
63 }
64
65 submodule_free(the_repository);
66
67 return 0;
68 }