scalar clone: add --no-maintenance option

When creating a new enlistment via 'scalar clone', the default is to set up situations that work for most user scenarios. Background maintenance is one of those highly-recommended options for most users. However, when using 'scalar clone' to create an enlistment in a different situation, such as prepping a VM image, it may be valuable to disable background maintenance so the manual maintenance steps do not get blocked by concurrent background maintenance activities. Add a new --no-maintenance option to 'scalar clone'. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed May 7, 2025 at 01:50 UTC 882ce0c475167039ca368d34699e113042ea47ae
3 files changed +22 -5
Documentation/scalar.adoc
+6 -1
@@ -9,7 +9,7 @@ SYNOPSIS
9 --------
10 [verse]
11 scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
12 - [--[no-]src] <url> [<enlistment>]
12 + [--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]
13 scalar list
14 scalar register [--[no-]maintenance] [<enlistment>]
15 scalar unregister [<enlistment>]
@@ -97,6 +97,11 @@ cloning. If the HEAD at the remote did not point at any branch when
97 A sparse-checkout is initialized by default. This behavior can be
98 turned off via `--full-clone`.
99
100 +--[no-]maintenance::
101 + By default, `scalar clone` configures the enlistment to use Git's
102 + background maintenance feature. Use the `--no-maintenance` to skip
103 + this configuration.
104 +
105 List
106 ~~~~
107
scalar.c
+6 -3
@@ -426,7 +426,7 @@ static int cmd_clone(int argc, const char **argv)
426 const char *branch = NULL;
427 char *branch_to_free = NULL;
428 int full_clone = 0, single_branch = 0, show_progress = isatty(2);
429 - int src = 1, tags = 1;
429 + int src = 1, tags = 1, maintenance = 1;
430 struct option clone_options[] = {
431 OPT_STRING('b', "branch", &branch, N_("<branch>"),
432 N_("branch to checkout after clone")),
@@ -439,11 +439,13 @@ static int cmd_clone(int argc, const char **argv)
439 N_("create repository within 'src' directory")),
440 OPT_BOOL(0, "tags", &tags,
441 N_("specify if tags should be fetched during clone")),
442 + OPT_BOOL(0, "maintenance", &maintenance,
443 + N_("specify if background maintenance should be enabled")),
444 OPT_END(),
445 };
446 const char * const clone_usage[] = {
447 N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
446 - "\t[--[no-]src] [--[no-]tags] <url> [<enlistment>]"),
448 + "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]"),
449 NULL
450 };
451 const char *url;
@@ -565,7 +567,8 @@ static int cmd_clone(int argc, const char **argv)
567 if (res)
568 goto cleanup;
569
568 - res = register_dir(1);
570 + /* If --no-maintenance, then skip maintenance command entirely. */
571 + res = register_dir(maintenance);
572
573 cleanup:
574 free(branch_to_free);
t/t9211-scalar-clone.sh
+10 -1
@@ -177,7 +177,16 @@ test_expect_success 'progress without tty' '
177 test_expect_success 'scalar clone warns when background maintenance fails' '
178 GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
179 scalar clone "file://$(pwd)/to-clone" maint-fail 2>err &&
180 - grep "could not turn on maintenance" err
180 + grep "could not toggle maintenance" err
181 +'
182 +
183 +test_expect_success 'scalar clone --no-maintenance' '
184 + GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
185 + GIT_TRACE2_EVENT="$(pwd)/no-maint.event" \
186 + GIT_TRACE2_EVENT_DEPTH=100 \
187 + scalar clone --no-maintenance "file://$(pwd)/to-clone" no-maint 2>err &&
188 + ! grep "could not toggle maintenance" err &&
189 + test_subcommand ! git maintenance unregister --force <no-maint.event
190 '
191
192 test_expect_success '`scalar clone --no-src`' '