Skip to content

Commit 9816e24

Browse files
derrickstoleegitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c428216 commit 9816e24

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
612612

613613
static int cmd_register(int argc, const char **argv)
614614
{
615+
int maintenance = 1;
615616
struct option options[] = {
617+
OPT_BOOL(0, "maintenance", &maintenance,
618+
N_("specify if background maintenance should be enabled")),
616619
OPT_END(),
617620
};
618621
const char * const usage[] = {
619-
N_("scalar register [<enlistment>]"),
622+
N_("scalar register [--[no-]maintenance] [<enlistment>]"),
620623
NULL
621624
};
622625

@@ -625,7 +628,8 @@ static int cmd_register(int argc, const char **argv)
625628

626629
setup_enlistment_directory(argc, argv, usage, options, NULL);
627630

628-
return register_dir(1);
631+
/* If --no-maintenance, then leave maintenance as-is. */
632+
return register_dir(maintenance);
629633
}
630634

631635
static int get_scalar_repos(const char *key, const char *value,

t/t9210-scalar.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ test_expect_success 'scalar register warns when background maintenance fails' '
108108
git init register-repo &&
109109
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
110110
scalar register register-repo 2>err &&
111-
grep "could not turn on maintenance" err
111+
grep "could not toggle maintenance" err
112112
'
113113

114114
test_expect_success 'scalar unregister' '
@@ -129,6 +129,17 @@ 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+
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+
132143
test_expect_success 'set up repository to clone' '
133144
test_commit first &&
134145
test_commit second &&

0 commit comments

Comments
 (0)