зеркало из https://github.com/microsoft/git.git
scalar: add --no-src option
Some users have strong aversions to Scalar's opinion that the repository should be in a 'src' directory, even though it creates a clean slate for placing build outputs in adjacent directories. The --no-src option allows users to opt-out of the default behavior. The parse-opt logic automatically figures out that '--src' is a possible flag that negates '--no-src'. Signed-off-by: Derrick Stolee <derrickstolee@github.com>
This commit is contained in:
Родитель
5b626414bb
Коммит
91bb815a7f
|
@ -9,7 +9,7 @@ SYNOPSIS
|
|||
--------
|
||||
[verse]
|
||||
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
|
||||
[--local-cache-path <path>] [--cache-server-url <url>]
|
||||
[--local-cache-path <path>] [--cache-server-url <url>] [--[no-]src]
|
||||
<url> [<enlistment>]
|
||||
scalar list
|
||||
scalar register [<enlistment>]
|
||||
|
@ -83,6 +83,9 @@ remote-tracking branch for the branch this option was used for the initial
|
|||
cloning. If the HEAD at the remote did not point at any branch when
|
||||
`--single-branch` clone was made, no remote-tracking branch is created.
|
||||
|
||||
--no-src::
|
||||
Skip adding a `src` directory within the target enlistment.
|
||||
|
||||
--[no-]full-clone::
|
||||
A sparse-checkout is initialized by default. This behavior can be
|
||||
turned off via `--full-clone`.
|
||||
|
|
14
scalar.c
14
scalar.c
|
@ -707,6 +707,8 @@ static int cmd_clone(int argc, const char **argv)
|
|||
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
|
||||
const char *cache_server_url = NULL, *local_cache_root = NULL;
|
||||
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
|
||||
const char *enlistment_parent;
|
||||
int no_src = 0;
|
||||
struct option clone_options[] = {
|
||||
OPT_STRING('b', "branch", &branch, N_("<branch>"),
|
||||
N_("branch to checkout after clone")),
|
||||
|
@ -715,6 +717,8 @@ static int cmd_clone(int argc, const char **argv)
|
|||
OPT_BOOL(0, "single-branch", &single_branch,
|
||||
N_("only download metadata for the branch that will "
|
||||
"be checked out")),
|
||||
OPT_BOOL(0, "no-src", &no_src,
|
||||
N_("skip creating a 'src' directory")),
|
||||
OPT_STRING(0, "cache-server-url", &cache_server_url,
|
||||
N_("<url>"),
|
||||
N_("the url or friendly name of the cache server")),
|
||||
|
@ -765,7 +769,13 @@ static int cmd_clone(int argc, const char **argv)
|
|||
|
||||
ensure_absolute_path(enlistment, &enlistment);
|
||||
|
||||
dir = xstrfmt("%s/src", enlistment);
|
||||
if (!no_src) {
|
||||
dir = xstrfmt("%s/src", enlistment);
|
||||
enlistment_parent = "../..";
|
||||
} else {
|
||||
dir = xstrdup(enlistment);
|
||||
enlistment_parent = "..";
|
||||
}
|
||||
|
||||
if (!local_cache_root)
|
||||
local_cache_root = local_cache_root_abs =
|
||||
|
@ -806,7 +816,7 @@ static int cmd_clone(int argc, const char **argv)
|
|||
struct strbuf path = STRBUF_INIT;
|
||||
|
||||
strbuf_addstr(&path, enlistment);
|
||||
if (chdir("../..") < 0 ||
|
||||
if (chdir(enlistment_parent) < 0 ||
|
||||
remove_dir_recursively(&path, 0) < 0)
|
||||
die(_("'--local-cache-path' cannot be inside the src "
|
||||
"folder;\nCould not remove '%s'"), enlistment);
|
||||
|
|
|
@ -391,4 +391,12 @@ test_expect_success '`scalar delete` with existing repo' '
|
|||
test_path_is_missing existing
|
||||
'
|
||||
|
||||
test_expect_success '`scalar clone --no-src`' '
|
||||
scalar clone --src "file://$(pwd)" with-src &&
|
||||
scalar clone --no-src "file://$(pwd)" without-src &&
|
||||
|
||||
test_path_is_dir with-src/src &&
|
||||
test_path_is_missing without-src/src
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Загрузка…
Ссылка в новой задаче