]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-submodule-config.c
config: don't include config.h by default
[thirdparty/git.git] / t / helper / test-submodule-config.c
CommitLineData
959b5455 1#include "cache.h"
b2141fc1 2#include "config.h"
959b5455 3#include "submodule-config.h"
851e18c3 4#include "submodule.h"
959b5455 5
3f2e2297 6static void die_usage(int argc, const char **argv, const char *msg)
959b5455
HV
7{
8 fprintf(stderr, "%s\n", msg);
9 fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
10 exit(1);
11}
12
851e18c3
HV
13static int git_test_config(const char *var, const char *value, void *cb)
14{
15 return parse_submodule_config_option(var, value);
16}
17
3f2e2297 18int cmd_main(int argc, const char **argv)
959b5455 19{
3f2e2297 20 const char **arg = argv;
959b5455
HV
21 int my_argc = argc;
22 int output_url = 0;
23 int lookup_name = 0;
24
25 arg++;
26 my_argc--;
55cbe18e 27 while (arg[0] && starts_with(arg[0], "--")) {
959b5455
HV
28 if (!strcmp(arg[0], "--url"))
29 output_url = 1;
30 if (!strcmp(arg[0], "--name"))
31 lookup_name = 1;
32 arg++;
33 my_argc--;
34 }
35
36 if (my_argc % 2 != 0)
37 die_usage(argc, argv, "Wrong number of arguments.");
38
851e18c3
HV
39 setup_git_directory();
40 gitmodules_config();
41 git_config(git_test_config, NULL);
42
959b5455
HV
43 while (*arg) {
44 unsigned char commit_sha1[20];
45 const struct submodule *submodule;
46 const char *commit;
47 const char *path_or_name;
48
49 commit = arg[0];
50 path_or_name = arg[1];
51
52 if (commit[0] == '\0')
f449198e 53 hashclr(commit_sha1);
959b5455
HV
54 else if (get_sha1(commit, commit_sha1) < 0)
55 die_usage(argc, argv, "Commit not found.");
56
57 if (lookup_name) {
58 submodule = submodule_from_name(commit_sha1, path_or_name);
59 } else
60 submodule = submodule_from_path(commit_sha1, path_or_name);
61 if (!submodule)
62 die_usage(argc, argv, "Submodule not found.");
63
64 if (output_url)
65 printf("Submodule url: '%s' for path '%s'\n",
66 submodule->url, submodule->path);
67 else
68 printf("Submodule name: '%s' for path '%s'\n",
69 submodule->name, submodule->path);
70
71 arg += 2;
72 }
73
74 submodule_free();
75
76 return 0;
77}