Skip to content

Commit 3c6da6a

Browse files
derrickstoleedscho
authored andcommitted
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>
1 parent 1d252e9 commit 3c6da6a

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Documentation/scalar.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
12-
[--local-cache-path <path>] [--cache-server-url <url>]
12+
[--local-cache-path <path>] [--cache-server-url <url>] [--[no-]src]
1313
<url> [<enlistment>]
1414
scalar list
1515
scalar register [<enlistment>]
@@ -83,6 +83,9 @@ remote-tracking branch for the branch this option was used for the initial
8383
cloning. If the HEAD at the remote did not point at any branch when
8484
`--single-branch` clone was made, no remote-tracking branch is created.
8585

86+
--no-src::
87+
Skip adding a `src` directory within the target enlistment.
88+
8689
--[no-]full-clone::
8790
A sparse-checkout is initialized by default. This behavior can be
8891
turned off via `--full-clone`.

scalar.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ static int cmd_clone(int argc, const char **argv)
707707
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
708708
const char *cache_server_url = NULL, *local_cache_root = NULL;
709709
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
710+
const char *enlistment_parent;
711+
int no_src = 0;
710712
struct option clone_options[] = {
711713
OPT_STRING('b', "branch", &branch, N_("<branch>"),
712714
N_("branch to checkout after clone")),
@@ -715,6 +717,8 @@ static int cmd_clone(int argc, const char **argv)
715717
OPT_BOOL(0, "single-branch", &single_branch,
716718
N_("only download metadata for the branch that will "
717719
"be checked out")),
720+
OPT_BOOL(0, "no-src", &no_src,
721+
N_("skip creating a 'src' directory")),
718722
OPT_STRING(0, "cache-server-url", &cache_server_url,
719723
N_("<url>"),
720724
N_("the url or friendly name of the cache server")),
@@ -765,7 +769,13 @@ static int cmd_clone(int argc, const char **argv)
765769

766770
ensure_absolute_path(enlistment, &enlistment);
767771

768-
dir = xstrfmt("%s/src", enlistment);
772+
if (!no_src) {
773+
dir = xstrfmt("%s/src", enlistment);
774+
enlistment_parent = "../..";
775+
} else {
776+
dir = xstrdup(enlistment);
777+
enlistment_parent = "..";
778+
}
769779

770780
if (!local_cache_root)
771781
local_cache_root = local_cache_root_abs =
@@ -806,7 +816,7 @@ static int cmd_clone(int argc, const char **argv)
806816
struct strbuf path = STRBUF_INIT;
807817

808818
strbuf_addstr(&path, enlistment);
809-
if (chdir("../..") < 0 ||
819+
if (chdir(enlistment_parent) < 0 ||
810820
remove_dir_recursively(&path, 0) < 0)
811821
die(_("'--local-cache-path' cannot be inside the src "
812822
"folder;\nCould not remove '%s'"), enlistment);

t/t9210-scalar.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,12 @@ test_expect_success '`scalar delete` with existing repo' '
391391
test_path_is_missing existing
392392
'
393393

394+
test_expect_success '`scalar clone --no-src`' '
395+
scalar clone --src "file://$(pwd)" with-src &&
396+
scalar clone --no-src "file://$(pwd)" without-src &&
397+
398+
test_path_is_dir with-src/src &&
399+
test_path_is_missing without-src/src
400+
'
401+
394402
test_done

0 commit comments

Comments
 (0)