Skip to content

Commit

Permalink
scalar: add --[no-]src option
Browse files Browse the repository at this point in the history
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.

While adding options, make sure the usage output by 'scalar clone -h'
reports the same as the SYNOPSIS line in Documentation/scalar.txt.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
  • Loading branch information
derrickstolee committed Aug 9, 2023
1 parent a82fb66 commit c1c7e2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Documentation/scalar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ scalar - A tool for managing large Git repositories
SYNOPSIS
--------
[verse]
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
[--[no-]src] <url> [<enlistment>]
scalar list
scalar register [<enlistment>]
scalar unregister [<enlistment>]
Expand Down Expand Up @@ -80,6 +81,11 @@ 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::
Specify if the repository should be created within a `src` directory
within `<enlistment>`. This is the default behavior, so use
`--no-src` to opt-out of the creation of the `src` directory.

--[no-]full-clone::
A sparse-checkout is initialized by default. This behavior can be
turned off via `--full-clone`.
Expand Down
11 changes: 9 additions & 2 deletions scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ static int cmd_clone(int argc, const char **argv)
{
const char *branch = NULL;
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
int src = 1;
struct option clone_options[] = {
OPT_STRING('b', "branch", &branch, N_("<branch>"),
N_("branch to checkout after clone")),
Expand All @@ -417,10 +418,13 @@ 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, "src", &src,
N_("create repository within 'src' directory")),
OPT_END(),
};
const char * const clone_usage[] = {
N_("scalar clone [<options>] [--] <repo> [<dir>]"),
N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
"\t[--[no-]src] <url> [<enlistment>]"),
NULL
};
const char *url;
Expand Down Expand Up @@ -456,7 +460,10 @@ static int cmd_clone(int argc, const char **argv)
if (is_directory(enlistment))
die(_("directory '%s' exists already"), enlistment);

dir = xstrfmt("%s/src", enlistment);
if (src)
dir = xstrfmt("%s/src", enlistment);
else
dir = xstrdup(enlistment);

strbuf_reset(&buf);
if (branch)
Expand Down
8 changes: 8 additions & 0 deletions t/t9211-scalar-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,12 @@ test_expect_success 'scalar clone warns when background maintenance fails' '
grep "could not turn on maintenance" err
'

test_expect_success '`scalar clone --no-src`' '
scalar clone --src "file://$(pwd)/to-clone" with-src &&
scalar clone --no-src "file://$(pwd)/to-clone" without-src &&
test_path_is_dir with-src/src &&
test_path_is_missing without-src/src
'

test_done

0 comments on commit c1c7e2f

Please sign in to comment.