diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-11-18 13:32:53 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-11-18 13:32:53 -0800 |
commit | 7660da161821ab79b8ecd5019c28843ed7e770a6 (patch) | |
tree | d0993b4af829e0275d6ff7cd0f87b17f69819b7c /t | |
parent | Merge branch 'pw/rebase-i-orig-head' (diff) | |
parent | maintenance: add troubleshooting guide to docs (diff) | |
download | tgif-7660da161821ab79b8ecd5019c28843ed7e770a6.tar.xz |
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')
-rw-r--r-- | t/helper/test-crontab.c | 35 | ||||
-rw-r--r-- | t/helper/test-tool.c | 1 | ||||
-rw-r--r-- | t/helper/test-tool.h | 1 | ||||
-rwxr-xr-x | t/t0068-for-each-repo.sh | 30 | ||||
-rwxr-xr-x | t/t7900-maintenance.sh | 159 | ||||
-rw-r--r-- | t/test-lib.sh | 7 |
6 files changed, 232 insertions, 1 deletions
diff --git a/t/helper/test-crontab.c b/t/helper/test-crontab.c new file mode 100644 index 0000000000..e7c0137a47 --- /dev/null +++ b/t/helper/test-crontab.c @@ -0,0 +1,35 @@ +#include "test-tool.h" +#include "cache.h" + +/* + * Usage: test-tool cron <file> [-l] + * + * If -l is specified, then write the contents of <file> to stdout. + * Otherwise, write from stdin into <file>. + */ +int cmd__crontab(int argc, const char **argv) +{ + int a; + FILE *from, *to; + + if (argc == 3 && !strcmp(argv[2], "-l")) { + from = fopen(argv[1], "r"); + if (!from) + return 0; + to = stdout; + } else if (argc == 2) { + from = stdin; + to = fopen(argv[1], "w"); + } else + return error("unknown arguments"); + + while ((a = fgetc(from)) != EOF) + fputc(a, to); + + if (argc == 3) + fclose(from); + else + fclose(to); + + return 0; +} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index a0d3966b29..cab19a9eb5 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -18,6 +18,7 @@ static struct test_cmd cmds[] = { { "bloom", cmd__bloom }, { "chmtime", cmd__chmtime }, { "config", cmd__config }, + { "crontab", cmd__crontab }, { "ctype", cmd__ctype }, { "date", cmd__date }, { "delta", cmd__delta }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 07034d3f38..1467f003af 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -8,6 +8,7 @@ int cmd__advise_if_enabled(int argc, const char **argv); int cmd__bloom(int argc, const char **argv); int cmd__chmtime(int argc, const char **argv); int cmd__config(int argc, const char **argv); +int cmd__crontab(int argc, const char **argv); int cmd__ctype(int argc, const char **argv); int cmd__date(int argc, const char **argv); int cmd__delta(int argc, const char **argv); diff --git a/t/t0068-for-each-repo.sh b/t/t0068-for-each-repo.sh new file mode 100755 index 0000000000..136b4ec839 --- /dev/null +++ b/t/t0068-for-each-repo.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +test_description='git for-each-repo builtin' + +. ./test-lib.sh + +test_expect_success 'run based on configured value' ' + git init one && + git init two && + git init three && + git -C two commit --allow-empty -m "DID NOT RUN" && + git config run.key "$TRASH_DIRECTORY/one" && + git config --add run.key "$TRASH_DIRECTORY/three" && + git for-each-repo --config=run.key commit --allow-empty -m "ran" && + git -C one log -1 --pretty=format:%s >message && + grep ran message && + git -C two log -1 --pretty=format:%s >message && + ! grep ran message && + git -C three log -1 --pretty=format:%s >message && + grep ran message && + git for-each-repo --config=run.key -- commit --allow-empty -m "ran again" && + git -C one log -1 --pretty=format:%s >message && + grep again message && + git -C two log -1 --pretty=format:%s >message && + ! grep again message && + git -C three log -1 --pretty=format:%s >message && + grep again message +' + +test_done 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 diff --git a/t/test-lib.sh b/t/test-lib.sh index fa347ed3e1..a863ccee7e 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1711,6 +1711,7 @@ test_lazy_prereq SHA1 ' test_lazy_prereq REBASE_P ' test -z "$GIT_TEST_SKIP_REBASE_P" ' + # Special-purpose prereq for transitioning to a new default branch name: # Some tests need more than just a mindless (case-preserving) s/master/main/g # replacement. The non-trivial adjustments are guarded behind this @@ -1718,3 +1719,9 @@ test_lazy_prereq REBASE_P ' test_lazy_prereq PREPARE_FOR_MAIN_BRANCH ' test "$GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME" = main ' + +# Ensure that no test accidentally triggers a Git command +# that runs 'crontab', affecting a user's cron schedule. +# Tests that verify the cron integration must set this locally +# to avoid errors. +GIT_TEST_CRONTAB="exit 1" |