t4202: refactor test
[gitweb.git] / builtin / submodule--helper.c
index 7f0941ddc340583384ef1a463f34360afc16c369..926d2051623be390d5de2611d81d5fe9f39a8169 100644 (file)
@@ -287,10 +287,8 @@ static int module_list(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, module_list_options,
                             git_submodule_helper_usage, 0);
 
-       if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) {
-               printf("#unmatched\n");
+       if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
                return 1;
-       }
 
        for (i = 0; i < list.nr; i++) {
                const struct cache_entry *ce = list.entries[i];
@@ -442,6 +440,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
 
        return 0;
 }
+
 static int clone_submodule(const char *path, const char *gitdir, const char *url,
                           const char *depth, const char *reference, int quiet)
 {
@@ -463,7 +462,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
        argv_array_push(&cp.args, path);
 
        cp.git_cmd = 1;
-       cp.env = local_repo_env;
+       prepare_submodule_repo_env(&cp.env_array);
        cp.no_stdin = 1;
 
        return run_command(&cp);
@@ -504,16 +503,17 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 
        const char *const git_submodule_helper_usage[] = {
                N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
-                  "[--reference <repository>] [--name <name>] [--url <url>]"
-                  "[--depth <depth>] [--] [<path>...]"),
+                  "[--reference <repository>] [--name <name>] [--depth <depth>] "
+                  "--url <url> --path <path>"),
                NULL
        };
 
        argc = parse_options(argc, argv, prefix, module_clone_options,
                             git_submodule_helper_usage, 0);
 
-       if (!path || !*path)
-               die(_("submodule--helper: unspecified or empty --path"));
+       if (argc || !url || !path || !*path)
+               usage_with_options(git_submodule_helper_usage,
+                                  module_clone_options);
 
        strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
        sm_gitdir = xstrdup(absolute_path(sb.buf));
@@ -831,6 +831,17 @@ static int update_clone(int argc, const char **argv, const char *prefix)
        return 0;
 }
 
+static int resolve_relative_path(int argc, const char **argv, const char *prefix)
+{
+       struct strbuf sb = STRBUF_INIT;
+       if (argc != 3)
+               die("submodule--helper relative_path takes exactly 2 arguments, got %d", argc);
+
+       printf("%s", relative_path(argv[1], argv[2], &sb));
+       strbuf_release(&sb);
+       return 0;
+}
+
 struct cmd_struct {
        const char *cmd;
        int (*fn)(int, const char **, const char *);
@@ -841,6 +852,7 @@ static struct cmd_struct commands[] = {
        {"name", module_name},
        {"clone", module_clone},
        {"update-clone", update_clone},
+       {"relative-path", resolve_relative_path},
        {"resolve-relative-url", resolve_relative_url},
        {"resolve-relative-url-test", resolve_relative_url_test},
        {"init", module_init}