Skip to content

Commit 1eac7d8

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 <[email protected]>
1 parent a9c043c commit 1eac7d8

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
@@ -699,6 +699,8 @@ static int cmd_clone(int argc, const char **argv)
699699
int full_clone = 0, single_branch = 0, dummy = 0;
700700
const char *cache_server_url = NULL, *local_cache_root = NULL;
701701
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
702+
const char *enlistment_parent;
703+
int no_src = 0;
702704
struct option clone_options[] = {
703705
OPT_STRING('b', "branch", &branch, N_("<branch>"),
704706
N_("branch to checkout after clone")),
@@ -707,6 +709,8 @@ static int cmd_clone(int argc, const char **argv)
707709
OPT_BOOL(0, "single-branch", &single_branch,
708710
N_("only download metadata for the branch that will "
709711
"be checked out")),
712+
OPT_BOOL(0, "no-src", &no_src,
713+
N_("skip creating a 'src' directory")),
710714
OPT_STRING(0, "cache-server-url", &cache_server_url,
711715
N_("<url>"),
712716
N_("the url or friendly name of the cache server")),
@@ -757,7 +761,13 @@ static int cmd_clone(int argc, const char **argv)
757761

758762
ensure_absolute_path(enlistment, &enlistment);
759763

760-
dir = xstrfmt("%s/src", enlistment);
764+
if (!no_src) {
765+
dir = xstrfmt("%s/src", enlistment);
766+
enlistment_parent = "../..";
767+
} else {
768+
dir = xstrdup(enlistment);
769+
enlistment_parent = "..";
770+
}
761771

762772
if (!local_cache_root)
763773
local_cache_root = local_cache_root_abs =
@@ -798,7 +808,7 @@ static int cmd_clone(int argc, const char **argv)
798808
struct strbuf path = STRBUF_INIT;
799809

800810
strbuf_addstr(&path, enlistment);
801-
if (chdir("../..") < 0 ||
811+
if (chdir(enlistment_parent) < 0 ||
802812
remove_dir_recursively(&path, 0) < 0)
803813
die(_("'--local-cache-path' cannot be inside the src "
804814
"folder;\nCould not remove '%s'"), enlistment);

t/t9210-scalar.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,12 @@ test_expect_success '`scalar delete` with existing repo' '
384384
test_path_is_missing existing
385385
'
386386

387+
test_expect_success '`scalar clone --no-src`' '
388+
scalar clone --src "file://$(pwd)" with-src &&
389+
scalar clone --no-src "file://$(pwd)" without-src &&
390+
391+
test_path_is_dir with-src/src &&
392+
test_path_is_missing without-src/src
393+
'
394+
387395
test_done

0 commit comments

Comments
 (0)