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 this creates a clean slate for placing build artifacts in adjacent directories. The new --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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Aug 28, 2023 at 13:52 UTC
4527db8ff8c61b173e4c2533b53d34d019a6f061
3 files changed
+28
-3
Documentation/scalar.txt
+7
-1
@@ -8,7 +8,8 @@ scalar - A tool for managing large Git repositories
8
SYNOPSIS
9
--------
10
[verse]
11
-scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
11
+scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
12
+ [--[no-]src] <url> [<enlistment>]
13
scalar list
14
scalar register [<enlistment>]
15
scalar unregister [<enlistment>]
@@ -80,6 +81,11 @@ remote-tracking branch for the branch this option was used for the initial
81
cloning. If the HEAD at the remote did not point at any branch when
82
`--single-branch` clone was made, no remote-tracking branch is created.
83
84
+--[no-]src::
85
+ By default, `scalar clone` places the cloned repository within a
86
+ `<entlistment>/src` directory. Use `--no-src` to place the cloned
87
+ repository directly in the `<enlistment>` directory.
88
+
89
--[no-]full-clone::
90
A sparse-checkout is initialized by default. This behavior can be
91
turned off via `--full-clone`.
scalar.c
+9
-2
@@ -409,6 +409,7 @@ static int cmd_clone(int argc, const char **argv)
409
{
410
const char *branch = NULL;
411
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
412
+ int src = 1;
413
struct option clone_options[] = {
414
OPT_STRING('b', "branch", &branch, N_("<branch>"),
415
N_("branch to checkout after clone")),
@@ -417,10 +418,13 @@ static int cmd_clone(int argc, const char **argv)
418
OPT_BOOL(0, "single-branch", &single_branch,
419
N_("only download metadata for the branch that will "
420
"be checked out")),
421
+ OPT_BOOL(0, "src", &src,
422
+ N_("create repository within 'src' directory")),
423
OPT_END(),
424
};
425
const char * const clone_usage[] = {
423
- N_("scalar clone [<options>] [--] <repo> [<dir>]"),
426
+ N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
427
+ "\t[--[no-]src] <url> [<enlistment>]"),
428
NULL
429
};
430
const char *url;
@@ -456,7 +460,10 @@ static int cmd_clone(int argc, const char **argv)
460
if (is_directory(enlistment))
461
die(_("directory '%s' exists already"), enlistment);
462
459
- dir = xstrfmt("%s/src", enlistment);
463
+ if (src)
464
+ dir = xstrfmt("%s/src", enlistment);
465
+ else
466
+ dir = xstrdup(enlistment);
467
468
strbuf_reset(&buf);
469
if (branch)
t/t9211-scalar-clone.sh
+12
@@ -180,4 +180,16 @@ test_expect_success 'scalar clone warns when background maintenance fails' '
180
grep "could not turn on maintenance" err
181
'
182
183
+test_expect_success '`scalar clone --no-src`' '
184
+ scalar clone --src "file://$(pwd)/to-clone" with-src &&
185
+ scalar clone --no-src "file://$(pwd)/to-clone" without-src &&
186
+
187
+ test_path_is_dir with-src/src &&
188
+ test_path_is_missing without-src/src &&
189
+
190
+ (cd with-src/src && ls ?*) >with &&
191
+ (cd without-src && ls ?*) >without &&
192
+ test_cmp with without
193
+'
194
+
195
test_done