Merge branch 'ds/scalar-no-maintenance' into seen

Two "scalar" subcommands that adds a repository that hasn't been
under "scalar"'s control are taught an option not to enable the
scheduled maintenance on it.

* ds/scalar-no-maintenance:
  scalar clone: add --no-maintenance option
  scalar register: add --no-maintenance option
Junio C Hamano 2025-05-01 14:07:27 -07:00
commit bfe24fdd42
4 changed files with 40 additions and 11 deletions

View File

@ -9,9 +9,9 @@ SYNOPSIS
--------
[verse]
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
[--[no-]src] <url> [<enlistment>]
[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]
scalar list
scalar register [<enlistment>]
scalar register [--[no-]maintenance] [<enlistment>]
scalar unregister [<enlistment>]
scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
scalar reconfigure [ --all | <enlistment> ]
@ -97,6 +97,11 @@ cloning. If the HEAD at the remote did not point at any branch when
A sparse-checkout is initialized by default. This behavior can be
turned off via `--full-clone`.

--[no-]maintenance::
By default, `scalar clone` configures the enlistment to use Git's
background maintenance feature. Use the `--no-maintenance` to skip
this configuration.

List
~~~~

@ -117,6 +122,12 @@ Note: when this subcommand is called in a worktree that is called `src/`, its
parent directory is considered to be the Scalar enlistment. If the worktree is
_not_ called `src/`, it itself will be considered to be the Scalar enlistment.

--[no-]maintenance::
By default, `scalar register` configures the enlistment to use Git's
background maintenance feature. Use the `--no-maintenance` to skip
this configuration. This does not disable any maintenance that may
already be enabled in other ways.

Unregister
~~~~~~~~~~


View File

@ -260,7 +260,7 @@ static int stop_fsmonitor_daemon(void)
return 0;
}

static int register_dir(void)
static int register_dir(int maintenance)
{
if (add_or_remove_enlistment(1))
return error(_("could not add enlistment"));
@ -268,7 +268,7 @@ static int register_dir(void)
if (set_recommended_config(0))
return error(_("could not set recommended config"));

if (toggle_maintenance(1))
if (toggle_maintenance(maintenance))
warning(_("could not turn on maintenance"));

if (have_fsmonitor_support() && start_fsmonitor_daemon()) {
@ -412,7 +412,7 @@ static int cmd_clone(int argc, const char **argv)
const char *branch = NULL;
char *branch_to_free = NULL;
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
int src = 1, tags = 1;
int src = 1, tags = 1, maintenance = 1;
struct option clone_options[] = {
OPT_STRING('b', "branch", &branch, N_("<branch>"),
N_("branch to checkout after clone")),
@ -425,11 +425,13 @@ static int cmd_clone(int argc, const char **argv)
N_("create repository within 'src' directory")),
OPT_BOOL(0, "tags", &tags,
N_("specify if tags should be fetched during clone")),
OPT_BOOL(0, "maintenance", &maintenance,
N_("specify if background maintenance should be enabled")),
OPT_END(),
};
const char * const clone_usage[] = {
N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
"\t[--[no-]src] [--[no-]tags] <url> [<enlistment>]"),
"\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]"),
NULL
};
const char *url;
@ -551,7 +553,7 @@ static int cmd_clone(int argc, const char **argv)
if (res)
goto cleanup;

res = register_dir();
res = register_dir(maintenance);

cleanup:
free(branch_to_free);
@ -598,11 +600,14 @@ static int cmd_list(int argc, const char **argv UNUSED)

static int cmd_register(int argc, const char **argv)
{
int maintenance = 1;
struct option options[] = {
OPT_BOOL(0, "maintenance", &maintenance,
N_("specify if background maintenance should be enabled")),
OPT_END(),
};
const char * const usage[] = {
N_("scalar register [<enlistment>]"),
N_("scalar register [--[no-]maintenance] [<enlistment>]"),
NULL
};

@ -611,7 +616,7 @@ static int cmd_register(int argc, const char **argv)

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

return register_dir();
return register_dir(maintenance);
}

static int get_scalar_repos(const char *key, const char *value,
@ -804,13 +809,13 @@ static int cmd_run(int argc, const char **argv)
strbuf_release(&buf);

if (i == 0)
return register_dir();
return register_dir(1);

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

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

View File

@ -129,6 +129,13 @@ test_expect_success 'scalar unregister' '
scalar unregister vanish
'

test_expect_success 'scalar register --no-maintenance' '
git init register-no-maint &&
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
scalar register --no-maintenance register-no-maint 2>err &&
test_must_be_empty err
'

test_expect_success 'set up repository to clone' '
test_commit first &&
test_commit second &&

View File

@ -180,6 +180,12 @@ test_expect_success 'scalar clone warns when background maintenance fails' '
grep "could not turn on maintenance" err
'

test_expect_success 'scalar clone --no-maintenance' '
GIT_TEST_MAINT_SCHEDULER="crontab:false,launchctl:false,schtasks:false" \
scalar clone --no-maintenance "file://$(pwd)/to-clone" no-maint 2>err &&
! grep "could not turn on maintenance" err
'

test_expect_success '`scalar clone --no-src`' '
scalar clone --src "file://$(pwd)/to-clone" with-src &&
scalar clone --no-src "file://$(pwd)/to-clone" without-src &&