scalar register: add --no-maintenance option

When registering a repository with Scalar to get the latest opinionated configuration, the 'scalar register' command will also set up background maintenance. This is a recommended feature for most user scenarios. However, this is not always recommended in some scenarios where background modifications may interfere with foreground activities. Specifically, setting up a clone for use in automation may require doing certain maintenance steps in the foreground that could become blocked by concurrent background maintenance operations. Allow the user to specify --no-maintenance to 'scalar register'. This requires updating the method prototype for register_dir(), so use the default of enabling this value when otherwise specified. 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 9816e24a78e3973164f324d50caa948ecfa2ab81
3 files changed +25 -4
Documentation/scalar.adoc
+7 -1
@@ -11,7 +11,7 @@ SYNOPSIS
11 scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
12 [--[no-]src] <url> [<enlistment>]
13 scalar list
14 -scalar register [<enlistment>]
14 +scalar register [--[no-]maintenance] [<enlistment>]
15 scalar unregister [<enlistment>]
16 scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
17 scalar reconfigure [ --all | <enlistment> ]
@@ -117,6 +117,12 @@ Note: when this subcommand is called in a worktree that is called `src/`, its
117 parent directory is considered to be the Scalar enlistment. If the worktree is
118 _not_ called `src/`, it itself will be considered to be the Scalar enlistment.
119
120 +--[no-]maintenance::
121 + By default, `scalar register` configures the enlistment to use Git's
122 + background maintenance feature. Use the `--no-maintenance` to skip
123 + this configuration. This does not disable any maintenance that may
124 + already be enabled in other ways.
125 +
126 Unregister
127 ~~~~~~~~~~
128
scalar.c
+6 -2
@@ -612,11 +612,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
612
613 static int cmd_register(int argc, const char **argv)
614 {
615 + int maintenance = 1;
616 struct option options[] = {
617 + OPT_BOOL(0, "maintenance", &maintenance,
618 + N_("specify if background maintenance should be enabled")),
619 OPT_END(),
620 };
621 const char * const usage[] = {
619 - N_("scalar register [<enlistment>]"),
622 + N_("scalar register [--[no-]maintenance] [<enlistment>]"),
623 NULL
624 };
625
@@ -625,7 +628,8 @@ static int cmd_register(int argc, const char **argv)
628
629 setup_enlistment_directory(argc, argv, usage, options, NULL);
630
628 - return register_dir(1);
631 + /* If --no-maintenance, then leave maintenance as-is. */
632 + return register_dir(maintenance);
633 }
634
635 static int get_scalar_repos(const char *key, const char *value,
t/t9210-scalar.sh
+12 -1
@@ -108,7 +108,7 @@ test_expect_success 'scalar register warns when background maintenance fails' '
108 git init register-repo &&
109 GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
110 scalar register register-repo 2>err &&
111 - grep "could not turn on maintenance" err
111 + grep "could not toggle maintenance" err
112 '
113
114 test_expect_success 'scalar unregister' '
@@ -129,6 +129,17 @@ test_expect_success 'scalar unregister' '
129 scalar unregister vanish
130 '
131
132 +test_expect_success 'scalar register --no-maintenance' '
133 + git init register-no-maint &&
134 + event_log="$(pwd)/no-maint.event" &&
135 + GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
136 + GIT_TRACE2_EVENT="$event_log" \
137 + GIT_TRACE2_EVENT_DEPTH=100 \
138 + scalar register --no-maintenance register-no-maint 2>err &&
139 + test_must_be_empty err &&
140 + test_subcommand ! git maintenance unregister --force <no-maint.event
141 +'
142 +
143 test_expect_success 'set up repository to clone' '
144 test_commit first &&
145 test_commit second &&