Signed-off-by: Elijah Newren <newren@xxxxxxxxx> --- builtin/clone.c | 28 ++++++++++++++++++++-------- t/t5601-clone.sh | 14 -------------- transport.h | 3 +++ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 19ed640..de0fb66 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -23,6 +23,7 @@ #include "branch.h" #include "remote.h" #include "run-command.h" +#include "quote.h" /* * Overall FIXMEs: @@ -33,7 +34,7 @@ * */ static const char * const builtin_clone_usage[] = { - "git clone [options] [--] <repo> [<dir>]", + "git clone [options] [--] <repo> [<dir>] [-- PATH1 PATH2...]", NULL }; @@ -375,6 +376,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) struct transport *transport = NULL; char *src_ref_prefix = "refs/heads/"; int err = 0; + int rest_argc = 0; struct refspec *refspec; const char *fetch_pattern; @@ -382,11 +384,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) junk_pid = getpid(); argc = parse_options(argc, argv, prefix, builtin_clone_options, - builtin_clone_usage, 0); - - if (argc > 2) - usage_msg_opt("Too many arguments.", - builtin_clone_usage, builtin_clone_options); + builtin_clone_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (argc == 0) usage_msg_opt("You must specify a repository to clone.", @@ -418,10 +416,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (is_local && option_depth) warning("--depth is ignored in local clones; use file:// instead."); - if (argc == 2) + if (argc >= 2 && strcmp(argv[1], "--") != 0) { dir = xstrdup(argv[1]); - else + rest_argc = 2; + } else { dir = guess_dir_name(repo_name, is_bundle, option_bare); + rest_argc = 1; + } strip_trailing_slashes(dir); dest_exists = !stat(dir, &buf); @@ -539,6 +540,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix) transport_set_option(transport, TRANS_OPT_UPLOADPACK, option_upload_pack); + if (argc > rest_argc) { + struct strbuf buf = STRBUF_INIT; + int ret; + + sq_quote_argv(&buf, &argv[rest_argc], 0); + ret = transport_set_option(transport, TRANS_OPT_SPARSE, + strbuf_detach(&buf, NULL)); + if (ret) + warning ("Sparse clone not supported!\n"); + } + refs = transport_get_remote_refs(transport); if (refs) { mapped_refs = wanted_peer_refs(refs, refspec); diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 987e0c8..17c6a30 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -17,20 +17,6 @@ test_expect_success setup ' ' -test_expect_success 'clone with excess parameters (1)' ' - - rm -fr dst && - test_must_fail git clone -n src dst junk - -' - -test_expect_success 'clone with excess parameters (2)' ' - - rm -fr dst && - test_must_fail git clone -n "file://$(pwd)/src" dst junk - -' - test_expect_success 'output from clone' ' rm -fr dst && git clone -n "file://$(pwd)/src" dst >output && diff --git a/transport.h b/transport.h index e803c0e..41e347a 100644 --- a/transport.h +++ b/transport.h @@ -127,6 +127,9 @@ struct transport *transport_get(struct remote *, const char *); /* Aggressively fetch annotated tags if possible */ #define TRANS_OPT_FOLLOWTAGS "followtags" +/* Fetch only certain paths */ +#define TRANS_OPT_SPARSE "sparse" + /** * Returns 0 if the option was used, non-zero otherwise. Prints a * message to stderr if the option is not used. -- 1.7.2.2.140.gd06af -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html