@@ -209,6 +209,12 @@ static int set_recommended_config(int reconfigure)
209209 return 0 ;
210210}
211211
212+ /**
213+ * Enable or disable the maintenance mode for the current repository:
214+ *
215+ * * If 'enable' is nonzero, run 'git maintenance start'.
216+ * * If 'enable' is zero, run 'git maintenance unregister --force'.
217+ */
212218static int toggle_maintenance (int enable )
213219{
214220 return run_git ("maintenance" ,
@@ -259,16 +265,25 @@ static int stop_fsmonitor_daemon(void)
259265 return 0 ;
260266}
261267
262- static int register_dir (void )
268+ /**
269+ * Register the current directory as a Scalar enlistment, and set the
270+ * recommended configuration.
271+ *
272+ * * If 'maintenance' is non-zero, then enable background maintenance.
273+ * * If 'maintenance' is zero, then leave background maintenance as it is
274+ * currently configured.
275+ */
276+ static int register_dir (int maintenance )
263277{
264278 if (add_or_remove_enlistment (1 ))
265279 return error (_ ("could not add enlistment" ));
266280
267281 if (set_recommended_config (0 ))
268282 return error (_ ("could not set recommended config" ));
269283
270- if (toggle_maintenance (1 ))
271- warning (_ ("could not turn on maintenance" ));
284+ if (maintenance &&
285+ toggle_maintenance (maintenance ))
286+ warning (_ ("could not toggle maintenance" ));
272287
273288 if (have_fsmonitor_support () && start_fsmonitor_daemon ()) {
274289 return error (_ ("could not start the FSMonitor daemon" ));
@@ -411,7 +426,7 @@ static int cmd_clone(int argc, const char **argv)
411426 const char * branch = NULL ;
412427 char * branch_to_free = NULL ;
413428 int full_clone = 0 , single_branch = 0 , show_progress = isatty (2 );
414- int src = 1 , tags = 1 ;
429+ int src = 1 , tags = 1 , maintenance = 1 ;
415430 struct option clone_options [] = {
416431 OPT_STRING ('b' , "branch" , & branch , N_ ("<branch>" ),
417432 N_ ("branch to checkout after clone" )),
@@ -424,11 +439,13 @@ static int cmd_clone(int argc, const char **argv)
424439 N_ ("create repository within 'src' directory" )),
425440 OPT_BOOL (0 , "tags" , & tags ,
426441 N_ ("specify if tags should be fetched during clone" )),
442+ OPT_BOOL (0 , "maintenance" , & maintenance ,
443+ N_ ("specify if background maintenance should be enabled" )),
427444 OPT_END (),
428445 };
429446 const char * const clone_usage [] = {
430447 N_ ("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
431- "\t[--[no-]src] [--[no-]tags] <url> [<enlistment>]" ),
448+ "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]" ),
432449 NULL
433450 };
434451 const char * url ;
@@ -550,7 +567,8 @@ static int cmd_clone(int argc, const char **argv)
550567 if (res )
551568 goto cleanup ;
552569
553- res = register_dir ();
570+ /* If --no-maintenance, then skip maintenance command entirely. */
571+ res = register_dir (maintenance );
554572
555573cleanup :
556574 free (branch_to_free );
@@ -597,11 +615,14 @@ static int cmd_list(int argc, const char **argv UNUSED)
597615
598616static int cmd_register (int argc , const char * * argv )
599617{
618+ int maintenance = 1 ;
600619 struct option options [] = {
620+ OPT_BOOL (0 , "maintenance" , & maintenance ,
621+ N_ ("specify if background maintenance should be enabled" )),
601622 OPT_END (),
602623 };
603624 const char * const usage [] = {
604- N_ ("scalar register [<enlistment>]" ),
625+ N_ ("scalar register [--[no-]maintenance] [ <enlistment>]" ),
605626 NULL
606627 };
607628
@@ -610,7 +631,8 @@ static int cmd_register(int argc, const char **argv)
610631
611632 setup_enlistment_directory (argc , argv , usage , options , NULL );
612633
613- return register_dir ();
634+ /* If --no-maintenance, then leave maintenance as-is. */
635+ return register_dir (maintenance );
614636}
615637
616638static int get_scalar_repos (const char * key , const char * value ,
@@ -646,13 +668,19 @@ static int remove_deleted_enlistment(struct strbuf *path)
646668static int cmd_reconfigure (int argc , const char * * argv )
647669{
648670 int all = 0 ;
671+ const char * maintenance_str = NULL ;
672+ int maintenance = 1 ; /* Enable maintenance by default. */
673+
649674 struct option options [] = {
650675 OPT_BOOL ('a' , "all" , & all ,
651676 N_ ("reconfigure all registered enlistments" )),
677+ OPT_STRING (0 , "maintenance" , & maintenance_str ,
678+ N_ ("(enable|disable|keep)" ),
679+ N_ ("signal how to adjust background maintenance" )),
652680 OPT_END (),
653681 };
654682 const char * const usage [] = {
655- N_ ("scalar reconfigure [--all | <enlistment>]" ),
683+ N_ ("scalar reconfigure [--maintenance=(enable|disable|keep)] [-- all | <enlistment>]" ),
656684 NULL
657685 };
658686 struct string_list scalar_repos = STRING_LIST_INIT_DUP ;
@@ -672,6 +700,18 @@ static int cmd_reconfigure(int argc, const char **argv)
672700 usage_msg_opt (_ ("--all or <enlistment>, but not both" ),
673701 usage , options );
674702
703+ if (maintenance_str ) {
704+ if (!strcmp (maintenance_str , "enable" ))
705+ maintenance = 1 ;
706+ else if (!strcmp (maintenance_str , "disable" ))
707+ maintenance = 0 ;
708+ else if (!strcmp (maintenance_str , "keep" ))
709+ maintenance = -1 ;
710+ else
711+ die (_ ("unknown mode for --maintenance option: %s" ),
712+ maintenance_str );
713+ }
714+
675715 git_config (get_scalar_repos , & scalar_repos );
676716
677717 for (size_t i = 0 ; i < scalar_repos .nr ; i ++ ) {
@@ -736,7 +776,8 @@ static int cmd_reconfigure(int argc, const char **argv)
736776 the_repository = old_repo ;
737777 repo_clear (& r );
738778
739- if (toggle_maintenance (1 ) >= 0 )
779+ if (maintenance >= 0 &&
780+ toggle_maintenance (maintenance ) >= 0 )
740781 succeeded = 1 ;
741782
742783loop_end :
@@ -803,13 +844,13 @@ static int cmd_run(int argc, const char **argv)
803844 strbuf_release (& buf );
804845
805846 if (i == 0 )
806- return register_dir ();
847+ return register_dir (1 );
807848
808849 if (i > 0 )
809850 return run_git ("maintenance" , "run" ,
810851 "--task" , tasks [i ].task , NULL );
811852
812- if (register_dir ())
853+ if (register_dir (1 ))
813854 return -1 ;
814855 for (i = 1 ; tasks [i ].arg ; i ++ )
815856 if (run_git ("maintenance" , "run" ,
0 commit comments