1407
return maintenance_run_tasks(&opts);
1408
}
1409
1410
-static const char builtin_maintenance_usage[] = N_("git maintenance run [<options>]");
1410
+static int maintenance_register(void)
1411
+{
1412
+ struct child_process config_set = CHILD_PROCESS_INIT;
1413
+ struct child_process config_get = CHILD_PROCESS_INIT;
1414
+
1415
+ /* There is no current repository, so skip registering it */
1416
+ if (!the_repository || !the_repository->gitdir)
1417
+ return 0;
1418
+
1419
+ config_get.git_cmd = 1;
1420
+ strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo",
1421
+ the_repository->worktree ? the_repository->worktree
1422
+ : the_repository->gitdir,
1423
+ NULL);
1424
+ config_get.out = -1;
1425
+
1426
+ if (start_command(&config_get))
1427
+ return error(_("failed to run 'git config'"));
1428
+
1429
+ /* We already have this value in our config! */
1430
+ if (!finish_command(&config_get))
1431
+ return 0;
1432
+
1433
+ config_set.git_cmd = 1;
1434
+ strvec_pushl(&config_set.args, "config", "--add", "--global", "maintenance.repo",
1435
+ the_repository->worktree ? the_repository->worktree
1436
+ : the_repository->gitdir,
1437
+ NULL);
1438
+
1439
+ return run_command(&config_set);
1440
+}
1441
+
1442
+static int maintenance_unregister(void)
1443
+{
1444
+ struct child_process config_unset = CHILD_PROCESS_INIT;
1445
+
1446
+ if (!the_repository || !the_repository->gitdir)
1447
+ return error(_("no current repository to unregister"));
1448
+
1449
+ config_unset.git_cmd = 1;
1450
+ strvec_pushl(&config_unset.args, "config", "--global", "--unset",
1451
+ "maintenance.repo",
1452
+ the_repository->worktree ? the_repository->worktree
1453
+ : the_repository->gitdir,
1454
+ NULL);
1455
+
1456
+ return run_command(&config_unset);
1457
+}
1458
+
1459
+static const char builtin_maintenance_usage[] = N_("git maintenance <subcommand> [<options>]");
1460
1461
int cmd_maintenance(int argc, const char **argv, const char *prefix)
1462
{
1466
1467
if (!strcmp(argv[1], "run"))
1468
return maintenance_run(argc - 1, argv + 1, prefix);
1469
+ if (!strcmp(argv[1], "register"))
1470
+ return maintenance_register();
1471
+ if (!strcmp(argv[1], "unregister"))
1472
+ return maintenance_unregister();
1473
1474
die(_("invalid subcommand: %s"), argv[1]);
1475
}