diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc index 7e4259c674..7753df3b43 100644 --- a/Documentation/scalar.adoc +++ b/Documentation/scalar.adoc @@ -9,9 +9,9 @@ SYNOPSIS -------- [verse] scalar clone [--single-branch] [--branch ] [--full-clone] - [--[no-]src] [] + [--[no-]src] [--[no-]tags] [--[no-]maintenance] [] scalar list -scalar register [] +scalar register [--[no-]maintenance] [] scalar unregister [] scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [] scalar reconfigure [ --all | ] @@ -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 ~~~~~~~~~~ diff --git a/scalar.c b/scalar.c index 49a98710a5..7140d5c82a 100644 --- a/scalar.c +++ b/scalar.c @@ -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_(""), 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 ] [--full-clone]\n" - "\t[--[no-]src] [--[no-]tags] []"), + "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] []"), 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 []"), + N_("scalar register [--[no-]maintenance] []"), 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", diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index a81662713e..a488f72de9 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -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 && diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh index 01f71910f5..b9c130db60 100755 --- a/t/t9211-scalar-clone.sh +++ b/t/t9211-scalar-clone.sh @@ -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 &&