Merge branch 'ps/maintenance-detach-fix'
Maintenance tasks other than "gc" now properly go background when "git maintenance" runs them. * ps/maintenance-detach-fix: run-command: fix detaching when running auto maintenance builtin/maintenance: add a `--detach` flag builtin/gc: add a `--detach` flag builtin/gc: stop processing log file on signal builtin/gc: fix leaking config values builtin/gc: refactor to read config into structure config: fix constness of out parameter for `git_config_get_expiry()`
This commit is contained in:
@ -7,6 +7,7 @@ test_description='prune'
|
||||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
||||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
day=$((60*60*24))
|
||||
|
@ -229,7 +229,7 @@ test_expect_success 'fetch --refetch triggers repacking' '
|
||||
|
||||
GIT_TRACE2_EVENT="$PWD/trace1.event" \
|
||||
git -C pc1 fetch --refetch origin &&
|
||||
test_subcommand git maintenance run --auto --no-quiet <trace1.event &&
|
||||
test_subcommand git maintenance run --auto --no-quiet --detach <trace1.event &&
|
||||
grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace1.event &&
|
||||
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace1.event &&
|
||||
|
||||
@ -238,7 +238,7 @@ test_expect_success 'fetch --refetch triggers repacking' '
|
||||
-c gc.autoPackLimit=0 \
|
||||
-c maintenance.incremental-repack.auto=1234 \
|
||||
-C pc1 fetch --refetch origin &&
|
||||
test_subcommand git maintenance run --auto --no-quiet <trace2.event &&
|
||||
test_subcommand git maintenance run --auto --no-quiet --detach <trace2.event &&
|
||||
grep \"param\":\"gc.autopacklimit\",\"value\":\"0\" trace2.event &&
|
||||
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"-1\" trace2.event &&
|
||||
|
||||
@ -247,7 +247,7 @@ test_expect_success 'fetch --refetch triggers repacking' '
|
||||
-c gc.autoPackLimit=1234 \
|
||||
-c maintenance.incremental-repack.auto=0 \
|
||||
-C pc1 fetch --refetch origin &&
|
||||
test_subcommand git maintenance run --auto --no-quiet <trace3.event &&
|
||||
test_subcommand git maintenance run --auto --no-quiet --detach <trace3.event &&
|
||||
grep \"param\":\"gc.autopacklimit\",\"value\":\"1\" trace3.event &&
|
||||
grep \"param\":\"maintenance.incremental-repack.auto\",\"value\":\"0\" trace3.event
|
||||
'
|
||||
|
@ -338,14 +338,14 @@ test_expect_success 'gc.maxCruftSize sets appropriate repack options' '
|
||||
test_subcommand $cruft_max_size_opts --max-cruft-size=3145728 <trace2.txt
|
||||
'
|
||||
|
||||
run_and_wait_for_auto_gc () {
|
||||
run_and_wait_for_gc () {
|
||||
# We read stdout from gc for the side effect of waiting until the
|
||||
# background gc process exits, closing its fd 9. Furthermore, the
|
||||
# variable assignment from a command substitution preserves the
|
||||
# exit status of the main gc process.
|
||||
# Note: this fd trickery doesn't work on Windows, but there is no
|
||||
# need to, because on Win the auto gc always runs in the foreground.
|
||||
doesnt_matter=$(git gc --auto 9>&1)
|
||||
doesnt_matter=$(git gc "$@" 9>&1)
|
||||
}
|
||||
|
||||
test_expect_success 'background auto gc does not run if gc.log is present and recent but does if it is old' '
|
||||
@ -361,7 +361,7 @@ test_expect_success 'background auto gc does not run if gc.log is present and re
|
||||
test-tool chmtime =-345600 .git/gc.log &&
|
||||
git gc --auto &&
|
||||
test_config gc.logexpiry 2.days &&
|
||||
run_and_wait_for_auto_gc &&
|
||||
run_and_wait_for_gc --auto &&
|
||||
ls .git/objects/pack/pack-*.pack >packs &&
|
||||
test_line_count = 1 packs
|
||||
'
|
||||
@ -391,11 +391,48 @@ test_expect_success 'background auto gc respects lock for all operations' '
|
||||
printf "%d %s" "$shell_pid" "$hostname" >.git/gc.pid &&
|
||||
|
||||
# our gc should exit zero without doing anything
|
||||
run_and_wait_for_auto_gc &&
|
||||
run_and_wait_for_gc --auto &&
|
||||
(ls -1 .git/refs/heads .git/reftable >actual || true) &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '--detach overrides gc.autoDetach=false' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
# Prepare the repository such that git-gc(1) ends up repacking.
|
||||
test_commit "$(test_oid blob17_1)" &&
|
||||
test_commit "$(test_oid blob17_2)" &&
|
||||
git config gc.autodetach false &&
|
||||
git config gc.auto 2 &&
|
||||
|
||||
# Note that we cannot use `test_cmp` here to compare stderr
|
||||
# because it may contain output from `set -x`.
|
||||
run_and_wait_for_gc --auto --detach 2>actual &&
|
||||
test_grep "Auto packing the repository in background for optimum performance." actual
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success '--no-detach overrides gc.autoDetach=true' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
# Prepare the repository such that git-gc(1) ends up repacking.
|
||||
test_commit "$(test_oid blob17_1)" &&
|
||||
test_commit "$(test_oid blob17_2)" &&
|
||||
git config gc.autodetach true &&
|
||||
git config gc.auto 2 &&
|
||||
|
||||
GIT_PROGRESS_DELAY=0 git gc --auto --no-detach 2>output &&
|
||||
test_grep "Auto packing the repository for optimum performance." output &&
|
||||
test_grep "Collecting referenced commits: 2, done." output
|
||||
)
|
||||
'
|
||||
|
||||
# DO NOT leave a detached auto gc process running near the end of the
|
||||
# test script: it can run long enough in the background to racily
|
||||
# interfere with the cleanup in 'test_done'.
|
||||
|
@ -49,22 +49,47 @@ test_expect_success 'run [--auto|--quiet]' '
|
||||
git maintenance run --auto 2>/dev/null &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
|
||||
git maintenance run --no-quiet 2>/dev/null &&
|
||||
test_subcommand git gc --quiet <run-no-auto.txt &&
|
||||
test_subcommand ! git gc --auto --quiet <run-auto.txt &&
|
||||
test_subcommand git gc --no-quiet <run-no-quiet.txt
|
||||
test_subcommand git gc --quiet --no-detach <run-no-auto.txt &&
|
||||
test_subcommand ! git gc --auto --quiet --no-detach <run-auto.txt &&
|
||||
test_subcommand git gc --no-quiet --no-detach <run-no-quiet.txt
|
||||
'
|
||||
|
||||
test_expect_success 'maintenance.auto config option' '
|
||||
GIT_TRACE2_EVENT="$(pwd)/default" git commit --quiet --allow-empty -m 1 &&
|
||||
test_subcommand git maintenance run --auto --quiet <default &&
|
||||
test_subcommand git maintenance run --auto --quiet --detach <default &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/true" \
|
||||
git -c maintenance.auto=true \
|
||||
commit --quiet --allow-empty -m 2 &&
|
||||
test_subcommand git maintenance run --auto --quiet <true &&
|
||||
test_subcommand git maintenance run --auto --quiet --detach <true &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/false" \
|
||||
git -c maintenance.auto=false \
|
||||
commit --quiet --allow-empty -m 3 &&
|
||||
test_subcommand ! git maintenance run --auto --quiet <false
|
||||
test_subcommand ! git maintenance run --auto --quiet --detach <false
|
||||
'
|
||||
|
||||
for cfg in maintenance.autoDetach gc.autoDetach
|
||||
do
|
||||
test_expect_success "$cfg=true config option" '
|
||||
test_when_finished "rm -f trace" &&
|
||||
test_config $cfg true &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
|
||||
test_subcommand git maintenance run --auto --quiet --detach <trace
|
||||
'
|
||||
|
||||
test_expect_success "$cfg=false config option" '
|
||||
test_when_finished "rm -f trace" &&
|
||||
test_config $cfg false &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
|
||||
test_subcommand git maintenance run --auto --quiet --no-detach <trace
|
||||
'
|
||||
done
|
||||
|
||||
test_expect_success "maintenance.autoDetach overrides gc.autoDetach" '
|
||||
test_when_finished "rm -f trace" &&
|
||||
test_config maintenance.autoDetach false &&
|
||||
test_config gc.autoDetach true &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace" git commit --quiet --allow-empty -m 1 &&
|
||||
test_subcommand git maintenance run --auto --quiet --no-detach <trace
|
||||
'
|
||||
|
||||
test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' '
|
||||
@ -129,9 +154,9 @@ test_expect_success 'run --task=<task>' '
|
||||
git maintenance run --task=commit-graph 2>/dev/null &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/run-both.txt" \
|
||||
git maintenance run --task=commit-graph --task=gc 2>/dev/null &&
|
||||
test_subcommand ! git gc --quiet <run-commit-graph.txt &&
|
||||
test_subcommand git gc --quiet <run-gc.txt &&
|
||||
test_subcommand git gc --quiet <run-both.txt &&
|
||||
test_subcommand ! git gc --quiet --no-detach <run-commit-graph.txt &&
|
||||
test_subcommand git gc --quiet --no-detach <run-gc.txt &&
|
||||
test_subcommand git gc --quiet --no-detach <run-both.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable --no-progress <run-commit-graph.txt &&
|
||||
test_subcommand ! git commit-graph write --split --reachable --no-progress <run-gc.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
|
||||
@ -908,4 +933,43 @@ test_expect_success 'failed schedule prevents config change' '
|
||||
done
|
||||
'
|
||||
|
||||
test_expect_success '--no-detach causes maintenance to not run in background' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
# Prepare the repository such that git-maintenance(1) ends up
|
||||
# outputting something.
|
||||
test_commit something &&
|
||||
git config set maintenance.gc.enabled false &&
|
||||
git config set maintenance.loose-objects.enabled true &&
|
||||
git config set maintenance.loose-objects.auto 1 &&
|
||||
git config set maintenance.incremental-repack.enabled true &&
|
||||
|
||||
# We have no better way to check whether or not the task ran in
|
||||
# the background than to verify whether it output anything. The
|
||||
# next testcase checks the reverse, making this somewhat safer.
|
||||
git maintenance run --no-detach >out 2>&1 &&
|
||||
test_line_count = 1 out
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success '--detach causes maintenance to run in background' '
|
||||
test_when_finished "rm -rf repo" &&
|
||||
git init repo &&
|
||||
(
|
||||
cd repo &&
|
||||
|
||||
test_commit something &&
|
||||
git config set maintenance.gc.enabled false &&
|
||||
git config set maintenance.loose-objects.enabled true &&
|
||||
git config set maintenance.loose-objects.auto 1 &&
|
||||
git config set maintenance.incremental-repack.enabled true &&
|
||||
|
||||
git maintenance run --detach >out 2>&1 &&
|
||||
test_must_be_empty out
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user