]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-submodule-config.c
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / helper / test-submodule-config.c
CommitLineData
b6188213 1#include "test-tool.h"
959b5455 2#include "cache.h"
b2141fc1 3#include "config.h"
959b5455 4#include "submodule-config.h"
851e18c3 5#include "submodule.h"
959b5455 6
3f2e2297 7static void die_usage(int argc, const char **argv, const char *msg)
959b5455
HV
8{
9 fprintf(stderr, "%s\n", msg);
10 fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
11 exit(1);
12}
13
b6188213 14int cmd__submodule_config(int argc, const char **argv)
959b5455 15{
3f2e2297 16 const char **arg = argv;
959b5455 17 int my_argc = argc;
959b5455
HV
18 int lookup_name = 0;
19
20 arg++;
21 my_argc--;
55cbe18e 22 while (arg[0] && starts_with(arg[0], "--")) {
959b5455
HV
23 if (!strcmp(arg[0], "--name"))
24 lookup_name = 1;
25 arg++;
26 my_argc--;
27 }
28
29 if (my_argc % 2 != 0)
30 die_usage(argc, argv, "Wrong number of arguments.");
31
851e18c3 32 setup_git_directory();
851e18c3 33
959b5455 34 while (*arg) {
cd73de47 35 struct object_id commit_oid;
959b5455
HV
36 const struct submodule *submodule;
37 const char *commit;
38 const char *path_or_name;
39
40 commit = arg[0];
41 path_or_name = arg[1];
42
43 if (commit[0] == '\0')
cd73de47 44 oidclr(&commit_oid);
45 else if (get_oid(commit, &commit_oid) < 0)
959b5455
HV
46 die_usage(argc, argv, "Commit not found.");
47
48 if (lookup_name) {
3b8fb393
SB
49 submodule = submodule_from_name(the_repository,
50 &commit_oid, path_or_name);
959b5455 51 } else
3b8fb393
SB
52 submodule = submodule_from_path(the_repository,
53 &commit_oid, path_or_name);
959b5455
HV
54 if (!submodule)
55 die_usage(argc, argv, "Submodule not found.");
56
255a1ae5
ÆAB
57 printf("Submodule name: '%s' for path '%s'\n", submodule->name,
58 submodule->path);
959b5455
HV
59
60 arg += 2;
61 }
62
f793b895 63 submodule_free(the_repository);
959b5455
HV
64
65 return 0;
66}