git/t/helper/test-submodule-config.c
Junio C Hamano 0807e57807 Merge branch 'en/header-split-cache-h'
Header clean-up.

* en/header-split-cache-h: (24 commits)
  protocol.h: move definition of DEFAULT_GIT_PORT from cache.h
  mailmap, quote: move declarations of global vars to correct unit
  treewide: reduce includes of cache.h in other headers
  treewide: remove double forward declaration of read_in_full
  cache.h: remove unnecessary includes
  treewide: remove cache.h inclusion due to pager.h changes
  pager.h: move declarations for pager.c functions from cache.h
  treewide: remove cache.h inclusion due to editor.h changes
  editor: move editor-related functions and declarations into common file
  treewide: remove cache.h inclusion due to object.h changes
  object.h: move some inline functions and defines from cache.h
  treewide: remove cache.h inclusion due to object-file.h changes
  object-file.h: move declarations for object-file.c functions from cache.h
  treewide: remove cache.h inclusion due to git-zlib changes
  git-zlib: move declarations for git-zlib functions from cache.h
  treewide: remove cache.h inclusion due to object-name.h changes
  object-name.h: move declarations for object-name.c functions from cache.h
  treewide: remove unnecessary cache.h inclusion
  treewide: be explicit about dependence on mem-pool.h
  treewide: be explicit about dependence on oid-array.h
  ...
2023-04-25 13:56:20 -07:00

68 lines
1.4 KiB
C

#include "test-tool.h"
#include "config.h"
#include "object-name.h"
#include "setup.h"
#include "submodule-config.h"
#include "submodule.h"
static void die_usage(int argc UNUSED, const char **argv, const char *msg)
{
fprintf(stderr, "%s\n", msg);
fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]);
exit(1);
}
int cmd__submodule_config(int argc, const char **argv)
{
const char **arg = argv;
int my_argc = argc;
int lookup_name = 0;
arg++;
my_argc--;
while (arg[0] && starts_with(arg[0], "--")) {
if (!strcmp(arg[0], "--name"))
lookup_name = 1;
arg++;
my_argc--;
}
if (my_argc % 2 != 0)
die_usage(argc, argv, "Wrong number of arguments.");
setup_git_directory();
while (*arg) {
struct object_id commit_oid;
const struct submodule *submodule;
const char *commit;
const char *path_or_name;
commit = arg[0];
path_or_name = arg[1];
if (commit[0] == '\0')
oidclr(&commit_oid);
else if (repo_get_oid(the_repository, commit, &commit_oid) < 0)
die_usage(argc, argv, "Commit not found.");
if (lookup_name) {
submodule = submodule_from_name(the_repository,
&commit_oid, path_or_name);
} else
submodule = submodule_from_path(the_repository,
&commit_oid, path_or_name);
if (!submodule)
die_usage(argc, argv, "Submodule not found.");
printf("Submodule name: '%s' for path '%s'\n", submodule->name,
submodule->path);
arg += 2;
}
submodule_free(the_repository);
return 0;
}