]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: move "resolve-relative-url-test" to a test-tool
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 31 Aug 2022 23:17:50 +0000 (01:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Sep 2022 16:16:23 +0000 (09:16 -0700)
As its name suggests the "resolve-relative-url-test" has never been
used outside of the test suite, see 63e95beb085 (submodule: port
resolve_relative_url from shell to C, 2016-04-15) for its original
addition.

Perhaps it would make sense to drop this code entirely, as we feel
that we've got enough indirect test coverage, but let's leave that
question to a possible follow-up change. For now let's keep the test
coverage this gives us.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c
t/helper/test-submodule.c
t/t0060-path-utils.sh

index 06307886080ca34378e55cec561674b6e8b143d2..246457ec2e90b764f821c368d133c7f639b9f745 100644 (file)
@@ -96,28 +96,6 @@ static char *resolve_relative_url(const char *rel_url, const char *up_path, int
        return resolved_url;
 }
 
-static int resolve_relative_url_test(int argc, const char **argv, const char *prefix)
-{
-       char *remoteurl, *res;
-       const char *up_path, *url;
-
-       if (argc != 4)
-               die("resolve-relative-url-test only accepts three arguments: <up_path> <remoteurl> <url>");
-
-       up_path = argv[1];
-       remoteurl = xstrdup(argv[2]);
-       url = argv[3];
-
-       if (!strcmp(up_path, "(null)"))
-               up_path = NULL;
-
-       res = relative_url(remoteurl, url, up_path);
-       puts(res);
-       free(res);
-       free(remoteurl);
-       return 0;
-}
-
 /* the result should be freed by the caller. */
 static char *get_submodule_displaypath(const char *path, const char *prefix)
 {
@@ -3273,7 +3251,6 @@ static struct cmd_struct commands[] = {
        {"clone", module_clone, SUPPORT_SUPER_PREFIX},
        {"add", module_add, 0},
        {"update", module_update, SUPPORT_SUPER_PREFIX},
-       {"resolve-relative-url-test", resolve_relative_url_test, 0},
        {"foreach", module_foreach, SUPPORT_SUPER_PREFIX},
        {"init", module_init, 0},
        {"status", module_status, SUPPORT_SUPER_PREFIX},
index 9f0eb440192eda53ded450d6c0784bab49d65fd1..e0e0c53d38619ded93c916b5f11685cf616a1de2 100644 (file)
@@ -2,6 +2,7 @@
 #include "test-tool-utils.h"
 #include "cache.h"
 #include "parse-options.h"
+#include "remote.h"
 #include "submodule-config.h"
 #include "submodule.h"
 
@@ -19,9 +20,17 @@ static const char *submodule_is_active_usage[] = {
        NULL
 };
 
+#define TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE \
+       "test-tool submodule resolve-relative-url <up_path> <remoteurl> <url>"
+static const char *submodule_resolve_relative_url_usage[] = {
+       TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE,
+       NULL,
+};
+
 static const char *submodule_usage[] = {
        TEST_TOOL_CHECK_NAME_USAGE,
        TEST_TOOL_IS_ACTIVE_USAGE,
+       TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE,
        NULL
 };
 
@@ -76,9 +85,42 @@ static int cmd__submodule_is_active(int argc, const char **argv)
        return !is_submodule_active(the_repository, argv[0]);
 }
 
+static int resolve_relative_url(int argc, const char **argv)
+{
+       char *remoteurl, *res;
+       const char *up_path, *url;
+
+       up_path = argv[0];
+       remoteurl = xstrdup(argv[1]);
+       url = argv[2];
+
+       if (!strcmp(up_path, "(null)"))
+               up_path = NULL;
+
+       res = relative_url(remoteurl, url, up_path);
+       puts(res);
+       free(res);
+       free(remoteurl);
+       return 0;
+}
+
+static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
+{
+       struct option options[] = {
+               OPT_END()
+       };
+       argc = parse_options(argc, argv, "test-tools", options,
+                            submodule_resolve_relative_url_usage, 0);
+       if (argc != 3)
+               usage_with_options(submodule_resolve_relative_url_usage, options);
+
+       return resolve_relative_url(argc, argv);
+}
+
 static struct test_cmd cmds[] = {
        { "check-name", cmd__submodule_check_name },
        { "is-active", cmd__submodule_is_active },
+       { "resolve-relative-url", cmd__submodule_resolve_relative_url},
 };
 
 int cmd__submodule(int argc, const char **argv)
index 1f2007e62b753c39992f681a711e4439e6577e3b..68e29c904a62c9ef51d6a1bfc3449795d50ac10f 100755 (executable)
@@ -22,7 +22,7 @@ relative_path() {
 
 test_submodule_relative_url() {
        test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" "
-               actual=\$(git submodule--helper resolve-relative-url-test '$1' '$2' '$3') &&
+               actual=\$(test-tool submodule resolve-relative-url '$1' '$2' '$3') &&
                test \"\$actual\" = '$4'
        "
 }