about summary refs log tree commit diff
path: root/third_party/git/t/helper/test-submodule-config.c
diff options
context:
space:
mode:
authorVincent Ambo <Vincent Ambo>2020-01-11T23·36+0000
committerVincent Ambo <Vincent Ambo>2020-01-11T23·40+0000
commit7ef0d62730840ded097b524104cc0a0904591a63 (patch)
treea670f96103667aeca4789a95d94ca0dff550c4ce /third_party/git/t/helper/test-submodule-config.c
parent6a2a3007077818e24a3d56fc492ada9206a10cf0 (diff)
parent1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5 (diff)
merge(third_party/git): Merge squashed git subtree at v2.23.0 r/373
Merge commit '1b593e1ea4d2af0f6444d9a7788d5d99abd6fde5' as 'third_party/git'
Diffstat (limited to 'third_party/git/t/helper/test-submodule-config.c')
-rw-r--r--third_party/git/t/helper/test-submodule-config.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/third_party/git/t/helper/test-submodule-config.c b/third_party/git/t/helper/test-submodule-config.c
new file mode 100644
index 000000000000..e2692746dfdb
--- /dev/null
+++ b/third_party/git/t/helper/test-submodule-config.c
@@ -0,0 +1,73 @@
+#include "test-tool.h"
+#include "cache.h"
+#include "config.h"
+#include "submodule-config.h"
+#include "submodule.h"
+
+static void die_usage(int argc, 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 output_url = 0;
+	int lookup_name = 0;
+
+	arg++;
+	my_argc--;
+	while (arg[0] && starts_with(arg[0], "--")) {
+		if (!strcmp(arg[0], "--url"))
+			output_url = 1;
+		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 (get_oid(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.");
+
+		if (output_url)
+			printf("Submodule url: '%s' for path '%s'\n",
+					submodule->url, submodule->path);
+		else
+			printf("Submodule name: '%s' for path '%s'\n",
+					submodule->name, submodule->path);
+
+		arg += 2;
+	}
+
+	submodule_free(the_repository);
+
+	return 0;
+}