Skip to content

Commit 6e6f68b

Browse files
committed
Merge branch 'ps/maintenance-detach-fix-more'
A tests for "git maintenance" that were broken on Windows have been corrected. * ps/maintenance-detach-fix-more: builtin/maintenance: fix loose objects task emitting pack hash t7900: exercise detaching via trace2 regions t7900: fix flaky test due to leaking background job
2 parents 1e8962e + 8311e3b commit 6e6f68b

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

builtin/gc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,12 @@ static int pack_loose(struct maintenance_run_opts *opts)
11601160

11611161
pack_proc.in = -1;
11621162

1163+
/*
1164+
* git-pack-objects(1) ends up writing the pack hash to stdout, which
1165+
* we do not care for.
1166+
*/
1167+
pack_proc.out = -1;
1168+
11631169
if (start_command(&pack_proc)) {
11641170
error(_("failed to start 'git pack-objects' process"));
11651171
return 1;
@@ -1429,8 +1435,11 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
14291435
free(lock_path);
14301436

14311437
/* Failure to daemonize is ok, we'll continue in foreground. */
1432-
if (opts->detach > 0)
1438+
if (opts->detach > 0) {
1439+
trace2_region_enter("maintenance", "detach", the_repository);
14331440
daemonize();
1441+
trace2_region_leave("maintenance", "detach", the_repository);
1442+
}
14341443

14351444
for (i = 0; !found_selected && i < TASK__COUNT; i++)
14361445
found_selected = tasks[i].selected_order >= 0;

t/t7900-maintenance.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,9 @@ test_expect_success '--no-detach causes maintenance to not run in background' '
947947
git config set maintenance.loose-objects.auto 1 &&
948948
git config set maintenance.incremental-repack.enabled true &&
949949
950-
# We have no better way to check whether or not the task ran in
951-
# the background than to verify whether it output anything. The
952-
# next testcase checks the reverse, making this somewhat safer.
953-
git maintenance run --no-detach >out 2>&1 &&
954-
test_line_count = 1 out
950+
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
951+
git maintenance run --no-detach >out 2>&1 &&
952+
! test_region maintenance detach trace.txt
955953
)
956954
'
957955

@@ -967,7 +965,28 @@ test_expect_success '--detach causes maintenance to run in background' '
967965
git config set maintenance.loose-objects.auto 1 &&
968966
git config set maintenance.incremental-repack.enabled true &&
969967
970-
git maintenance run --detach >out 2>&1 &&
968+
# The extra file descriptor gets inherited to the child
969+
# process, and by reading stdout we thus essentially wait for
970+
# that descriptor to get closed, which indicates that the child
971+
# is done, too.
972+
does_not_matter=$(GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
973+
git maintenance run --detach 9>&1) &&
974+
test_region maintenance detach trace.txt
975+
)
976+
'
977+
978+
test_expect_success 'repacking loose objects is quiet' '
979+
test_when_finished "rm -rf repo" &&
980+
git init repo &&
981+
(
982+
cd repo &&
983+
984+
test_commit something &&
985+
git config set maintenance.gc.enabled false &&
986+
git config set maintenance.loose-objects.enabled true &&
987+
git config set maintenance.loose-objects.auto 1 &&
988+
989+
git maintenance run --quiet >out 2>&1 &&
971990
test_must_be_empty out
972991
)
973992
'

0 commit comments

Comments
 (0)