]> git.ipfire.org Git - thirdparty/git.git/blame - 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
CommitLineData
b6188213 1#include "test-tool.h"
959b5455 2#include "cache.h"
b2141fc1 3#include "config.h"
dabab1d6 4#include "object-name.h"
e38da487 5#include "setup.h"
959b5455 6#include "submodule-config.h"
851e18c3 7#include "submodule.h"
959b5455 8
3f2e2297 9static void die_usage(int argc, const char **argv, const char *msg)
959b5455
HV
10{
11 fprintf(stderr, "%s\n", msg);
12 fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
13 exit(1);
14}
15
b6188213 16int cmd__submodule_config(int argc, const char **argv)
959b5455 17{
3f2e2297 18 const char **arg = argv;
959b5455 19 int my_argc = argc;
959b5455
HV
20 int lookup_name = 0;
21
22 arg++;
23 my_argc--;
55cbe18e 24 while (arg[0] && starts_with(arg[0], "--")) {
959b5455
HV
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
851e18c3 34 setup_git_directory();
851e18c3 35
959b5455 36 while (*arg) {
cd73de47 37 struct object_id commit_oid;
959b5455
HV
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')
cd73de47 46 oidclr(&commit_oid);
d850b7a5 47 else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
959b5455
HV
48 die_usage(argc, argv, "Commit not found.");
49
50 if (lookup_name) {
3b8fb393
SB
51 submodule = submodule_from_name(the_repository,
52 &commit_oid, path_or_name);
959b5455 53 } else
3b8fb393
SB
54 submodule = submodule_from_path(the_repository,
55 &commit_oid, path_or_name);
959b5455
HV
56 if (!submodule)
57 die_usage(argc, argv, "Submodule not found.");
58
255a1ae5
ÆAB
59 printf("Submodule name: '%s' for path '%s'\n", submodule->name,
60 submodule->path);
959b5455
HV
61
62 arg += 2;
63 }
64
f793b895 65 submodule_free(the_repository);
959b5455
HV
66
67 return 0;
68}