Skip to content

Commit a6affd3

Browse files
pks-tgitster
authored andcommitted
builtin/maintenance: add a --detach flag
Same as the preceding commit, add a `--[no-]detach` flag to the git-maintenance(1) command. This will be used in a subsequent commit to fix backgrounding of that command when configured with a non-standard set of tasks. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c7185df commit a6affd3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

builtin/gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,10 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
14261426
}
14271427
free(lock_path);
14281428

1429+
/* Failure to daemonize is ok, we'll continue in foreground. */
1430+
if (opts->detach > 0)
1431+
daemonize();
1432+
14291433
for (i = 0; !found_selected && i < TASK__COUNT; i++)
14301434
found_selected = tasks[i].selected_order >= 0;
14311435

@@ -1552,6 +1556,8 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
15521556
struct option builtin_maintenance_run_options[] = {
15531557
OPT_BOOL(0, "auto", &opts.auto_flag,
15541558
N_("run tasks based on the state of the repository")),
1559+
OPT_BOOL(0, "detach", &opts.detach,
1560+
N_("perform maintenance in the background")),
15551561
OPT_CALLBACK(0, "schedule", &opts.schedule, N_("frequency"),
15561562
N_("run tasks based on frequency"),
15571563
maintenance_opt_schedule),

t/t7900-maintenance.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,4 +908,43 @@ test_expect_success 'failed schedule prevents config change' '
908908
done
909909
'
910910

911+
test_expect_success '--no-detach causes maintenance to not run in background' '
912+
test_when_finished "rm -rf repo" &&
913+
git init repo &&
914+
(
915+
cd repo &&
916+
917+
# Prepare the repository such that git-maintenance(1) ends up
918+
# outputting something.
919+
test_commit something &&
920+
git config set maintenance.gc.enabled false &&
921+
git config set maintenance.loose-objects.enabled true &&
922+
git config set maintenance.loose-objects.auto 1 &&
923+
git config set maintenance.incremental-repack.enabled true &&
924+
925+
# We have no better way to check whether or not the task ran in
926+
# the background than to verify whether it output anything. The
927+
# next testcase checks the reverse, making this somewhat safer.
928+
git maintenance run --no-detach >out 2>&1 &&
929+
test_line_count = 1 out
930+
)
931+
'
932+
933+
test_expect_success '--detach causes maintenance to run in background' '
934+
test_when_finished "rm -rf repo" &&
935+
git init repo &&
936+
(
937+
cd repo &&
938+
939+
test_commit something &&
940+
git config set maintenance.gc.enabled false &&
941+
git config set maintenance.loose-objects.enabled true &&
942+
git config set maintenance.loose-objects.auto 1 &&
943+
git config set maintenance.incremental-repack.enabled true &&
944+
945+
git maintenance run --detach >out 2>&1 &&
946+
test_must_be_empty out
947+
)
948+
'
949+
911950
test_done

0 commit comments

Comments
 (0)