diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-11-19 00:32:53 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-11-19 00:32:53 +0300 |
commit | 7660da161821ab79b8ecd5019c28843ed7e770a6 (patch) | |
tree | d0993b4af829e0275d6ff7cd0f87b17f69819b7c /t/t7900-maintenance.sh | |
parent | c042c455d4ffb9b5ed0c280301b5661f3efad572 (diff) | |
parent | 0016b618182f642771dc589cf0090289f9fe1b4f (diff) |
Merge branch 'ds/maintenance-part-3'
Parts of "git maintenance" to ease writing crontab entries (and
other scheduling system configuration) for it.
* ds/maintenance-part-3:
maintenance: add troubleshooting guide to docs
maintenance: use 'incremental' strategy by default
maintenance: create maintenance.strategy config
maintenance: add start/stop subcommands
maintenance: add [un]register subcommands
for-each-repo: run subcommands on configured repos
maintenance: add --schedule option and config
maintenance: optionally skip --auto process
Diffstat (limited to 't/t7900-maintenance.sh')
-rwxr-xr-x | t/t7900-maintenance.sh | 159 |
1 files changed, 158 insertions, 1 deletions
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index b2def8bb16..d9e68bb2bf 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -9,7 +9,7 @@ GIT_TEST_MULTI_PACK_INDEX=0 test_expect_success 'help text' ' test_expect_code 129 git maintenance -h 2>err && - test_i18ngrep "usage: git maintenance run" err && + test_i18ngrep "usage: git maintenance <subcommand>" err && test_expect_code 128 git maintenance barf 2>err && test_i18ngrep "invalid subcommand: barf" err && test_expect_code 129 git maintenance 2>err && @@ -28,6 +28,19 @@ test_expect_success 'run [--auto|--quiet]' ' test_subcommand git gc --no-quiet <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 && + GIT_TRACE2_EVENT="$(pwd)/true" \ + git -c maintenance.auto=true \ + commit --quiet --allow-empty -m 2 && + test_subcommand git maintenance run --auto --quiet <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_expect_success 'maintenance.<task>.enabled' ' git config maintenance.gc.enabled false && git config maintenance.commit-graph.enabled true && @@ -284,4 +297,148 @@ test_expect_success 'maintenance.incremental-repack.auto' ' test_subcommand git multi-pack-index write --no-progress <trace-B ' +test_expect_success '--auto and --schedule incompatible' ' + test_must_fail git maintenance run --auto --schedule=daily 2>err && + test_i18ngrep "at most one" err +' + +test_expect_success 'invalid --schedule value' ' + test_must_fail git maintenance run --schedule=annually 2>err && + test_i18ngrep "unrecognized --schedule" err +' + +test_expect_success '--schedule inheritance weekly -> daily -> hourly' ' + git config maintenance.loose-objects.enabled true && + git config maintenance.loose-objects.schedule hourly && + git config maintenance.commit-graph.enabled true && + git config maintenance.commit-graph.schedule daily && + git config maintenance.incremental-repack.enabled true && + git config maintenance.incremental-repack.schedule weekly && + + GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \ + git maintenance run --schedule=hourly 2>/dev/null && + test_subcommand git prune-packed --quiet <hourly.txt && + test_subcommand ! git commit-graph write --split --reachable \ + --no-progress <hourly.txt && + test_subcommand ! git multi-pack-index write --no-progress <hourly.txt && + + GIT_TRACE2_EVENT="$(pwd)/daily.txt" \ + git maintenance run --schedule=daily 2>/dev/null && + test_subcommand git prune-packed --quiet <daily.txt && + test_subcommand git commit-graph write --split --reachable \ + --no-progress <daily.txt && + test_subcommand ! git multi-pack-index write --no-progress <daily.txt && + + GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \ + git maintenance run --schedule=weekly 2>/dev/null && + test_subcommand git prune-packed --quiet <weekly.txt && + test_subcommand git commit-graph write --split --reachable \ + --no-progress <weekly.txt && + test_subcommand git multi-pack-index write --no-progress <weekly.txt +' + +test_expect_success 'maintenance.strategy inheritance' ' + for task in commit-graph loose-objects incremental-repack + do + git config --unset maintenance.$task.schedule || return 1 + done && + + test_when_finished git config --unset maintenance.strategy && + git config maintenance.strategy incremental && + + GIT_TRACE2_EVENT="$(pwd)/incremental-hourly.txt" \ + git maintenance run --schedule=hourly --quiet && + GIT_TRACE2_EVENT="$(pwd)/incremental-daily.txt" \ + git maintenance run --schedule=daily --quiet && + + test_subcommand git commit-graph write --split --reachable \ + --no-progress <incremental-hourly.txt && + test_subcommand ! git prune-packed --quiet <incremental-hourly.txt && + test_subcommand ! git multi-pack-index write --no-progress \ + <incremental-hourly.txt && + + test_subcommand git commit-graph write --split --reachable \ + --no-progress <incremental-daily.txt && + test_subcommand git prune-packed --quiet <incremental-daily.txt && + test_subcommand git multi-pack-index write --no-progress \ + <incremental-daily.txt && + + # Modify defaults + git config maintenance.commit-graph.schedule daily && + git config maintenance.loose-objects.schedule hourly && + git config maintenance.incremental-repack.enabled false && + + GIT_TRACE2_EVENT="$(pwd)/modified-hourly.txt" \ + git maintenance run --schedule=hourly --quiet && + GIT_TRACE2_EVENT="$(pwd)/modified-daily.txt" \ + git maintenance run --schedule=daily --quiet && + + test_subcommand ! git commit-graph write --split --reachable \ + --no-progress <modified-hourly.txt && + test_subcommand git prune-packed --quiet <modified-hourly.txt && + test_subcommand ! git multi-pack-index write --no-progress \ + <modified-hourly.txt && + + test_subcommand git commit-graph write --split --reachable \ + --no-progress <modified-daily.txt && + test_subcommand git prune-packed --quiet <modified-daily.txt && + test_subcommand ! git multi-pack-index write --no-progress \ + <modified-daily.txt +' + +test_expect_success 'register and unregister' ' + test_when_finished git config --global --unset-all maintenance.repo && + git config --global --add maintenance.repo /existing1 && + git config --global --add maintenance.repo /existing2 && + git config --global --get-all maintenance.repo >before && + + git maintenance register && + test_cmp_config false maintenance.auto && + git config --global --get-all maintenance.repo >between && + cp before expect && + pwd >>expect && + test_cmp expect between && + + git maintenance unregister && + git config --global --get-all maintenance.repo >actual && + test_cmp before actual +' + +test_expect_success 'start from empty cron table' ' + GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start && + + # start registers the repo + git config --get --global maintenance.repo "$(pwd)" && + + grep "for-each-repo --config=maintenance.repo maintenance run --schedule=daily" cron.txt && + grep "for-each-repo --config=maintenance.repo maintenance run --schedule=hourly" cron.txt && + grep "for-each-repo --config=maintenance.repo maintenance run --schedule=weekly" cron.txt +' + +test_expect_success 'stop from existing schedule' ' + GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance stop && + + # stop does not unregister the repo + git config --get --global maintenance.repo "$(pwd)" && + + # Operation is idempotent + GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance stop && + test_must_be_empty cron.txt +' + +test_expect_success 'start preserves existing schedule' ' + echo "Important information!" >cron.txt && + GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start && + grep "Important information!" cron.txt +' + +test_expect_success 'register preserves existing strategy' ' + git config maintenance.strategy none && + git maintenance register && + test_config maintenance.strategy none && + git config --unset maintenance.strategy && + git maintenance register && + test_config maintenance.strategy incremental +' + test_done |