| 433 | } |
| 434 | |
| 435 | static int cmd_clone(int argc, const char **argv) |
| 436 | { |
| 437 | const char *branch = NULL; |
| 438 | char *branch_to_free = NULL; |
| 439 | int full_clone = 0, single_branch = 0, show_progress = isatty(2); |
| 440 | int src = 1, tags = 1, maintenance = 1; |
| 441 | struct option clone_options[] = { |
| 442 | OPT_STRING('b', "branch", &branch, N_("<branch>"), |
| 443 | N_("branch to checkout after clone")), |
| 444 | OPT_BOOL(0, "full-clone", &full_clone, |
| 445 | N_("when cloning, create full working directory")), |
| 446 | OPT_BOOL(0, "single-branch", &single_branch, |
| 447 | N_("only download metadata for the branch that will " |
| 448 | "be checked out")), |
| 449 | OPT_BOOL(0, "src", &src, |
| 450 | N_("create repository within 'src' directory")), |
| 451 | OPT_BOOL(0, "tags", &tags, |
| 452 | N_("specify if tags should be fetched during clone")), |
| 453 | OPT_BOOL(0, "maintenance", &maintenance, |
| 454 | N_("specify if background maintenance should be enabled")), |
| 455 | OPT_END(), |
| 456 | }; |
| 457 | const char * const clone_usage[] = { |
| 458 | N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n" |
| 459 | "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]"), |
| 460 | NULL |
| 461 | }; |
| 462 | const char *url; |
| 463 | char *enlistment = NULL, *dir = NULL; |
| 464 | struct strbuf buf = STRBUF_INIT; |
| 465 | int res; |
| 466 | |
| 467 | argc = parse_options(argc, argv, NULL, clone_options, clone_usage, 0); |
| 468 | |
| 469 | if (argc == 2) { |
| 470 | url = argv[0]; |
| 471 | enlistment = xstrdup(argv[1]); |
| 472 | } else if (argc == 1) { |
| 473 | url = argv[0]; |
| 474 | |
| 475 | strbuf_addstr(&buf, url); |
| 476 | /* Strip trailing slashes, if any */ |
| 477 | while (buf.len > 0 && is_dir_sep(buf.buf[buf.len - 1])) |
| 478 | strbuf_setlen(&buf, buf.len - 1); |
| 479 | /* Strip suffix `.git`, if any */ |
| 480 | strbuf_strip_suffix(&buf, ".git"); |
| 481 | |
| 482 | enlistment = find_last_dir_sep(buf.buf); |
| 483 | if (!enlistment) { |
| 484 | die(_("cannot deduce worktree name from '%s'"), url); |
| 485 | } |
| 486 | enlistment = xstrdup(enlistment + 1); |
| 487 | } else { |
| 488 | usage_msg_opt(_("You must specify a repository to clone."), |
| 489 | clone_usage, clone_options); |
| 490 | } |
| 491 | |
| 492 | if (is_directory(enlistment)) |
nothing calls this directly
no test coverage detected