Skip to content

Commit 4910bac

Browse files
committed
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 <[email protected]>
1 parent f65182a commit 4910bac

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Documentation/scalar.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SYNOPSIS
1111
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
1212
[--[no-]src] <url> [<enlistment>]
1313
scalar list
14-
scalar register [<enlistment>]
14+
scalar register [--[no-]maintenance] [<enlistment>]
1515
scalar unregister [<enlistment>]
1616
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
1717
scalar reconfigure [ --all | <enlistment> ]
@@ -117,6 +117,12 @@ Note: when this subcommand is called in a worktree that is called `src/`, its
117117
parent directory is considered to be the Scalar enlistment. If the worktree is
118118
_not_ called `src/`, it itself will be considered to be the Scalar enlistment.
119119

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+
120126
Unregister
121127
~~~~~~~~~~
122128

scalar.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,15 @@ static int stop_fsmonitor_daemon(void)
259259
return 0;
260260
}
261261

262-
static int register_dir(void)
262+
static int register_dir(int maintenance)
263263
{
264264
if (add_or_remove_enlistment(1))
265265
return error(_("could not add enlistment"));
266266

267267
if (set_recommended_config(0))
268268
return error(_("could not set recommended config"));
269269

270-
if (toggle_maintenance(1))
270+
if (toggle_maintenance(maintenance))
271271
warning(_("could not turn on maintenance"));
272272

273273
if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
@@ -550,7 +550,7 @@ static int cmd_clone(int argc, const char **argv)
550550
if (res)
551551
goto cleanup;
552552

553-
res = register_dir();
553+
res = register_dir(1);
554554

555555
cleanup:
556556
free(branch_to_free);
@@ -597,11 +597,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
597597

598598
static int cmd_register(int argc, const char **argv)
599599
{
600+
int maintenance = 1;
600601
struct option options[] = {
602+
OPT_BOOL(0, "maintenance", &maintenance,
603+
N_("specify if background maintenance should be enabled")),
601604
OPT_END(),
602605
};
603606
const char * const usage[] = {
604-
N_("scalar register [<enlistment>]"),
607+
N_("scalar register [--[no-]maintenance] [<enlistment>]"),
605608
NULL
606609
};
607610

@@ -610,7 +613,7 @@ static int cmd_register(int argc, const char **argv)
610613

611614
setup_enlistment_directory(argc, argv, usage, options, NULL);
612615

613-
return register_dir();
616+
return register_dir(maintenance);
614617
}
615618

616619
static int get_scalar_repos(const char *key, const char *value,
@@ -803,13 +806,13 @@ static int cmd_run(int argc, const char **argv)
803806
strbuf_release(&buf);
804807

805808
if (i == 0)
806-
return register_dir();
809+
return register_dir(1);
807810

808811
if (i > 0)
809812
return run_git("maintenance", "run",
810813
"--task", tasks[i].task, NULL);
811814

812-
if (register_dir())
815+
if (register_dir(1))
813816
return -1;
814817
for (i = 1; tasks[i].arg; i++)
815818
if (run_git("maintenance", "run",

t/t9210-scalar.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ test_expect_success 'scalar unregister' '
129129
scalar unregister vanish
130130
'
131131

132+
test_expect_success 'scalar register --no-maintenance' '
133+
git init register-no-maint &&
134+
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
135+
scalar register --no-maintenance register-no-maint 2>err &&
136+
test_must_be_empty err
137+
'
138+
132139
test_expect_success 'set up repository to clone' '
133140
test_commit first &&
134141
test_commit second &&

0 commit comments

Comments
 (0)