summaryrefslogtreecommitdiff
path: root/t/t7900-maintenance.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t7900-maintenance.sh')
-rwxr-xr-xt/t7900-maintenance.sh150
1 files changed, 142 insertions, 8 deletions
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index d9e68bb..1074009 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -7,6 +7,19 @@ test_description='git maintenance builtin'
GIT_TEST_COMMIT_GRAPH=0
GIT_TEST_MULTI_PACK_INDEX=0
+test_lazy_prereq XMLLINT '
+ xmllint --version
+'
+
+test_xmllint () {
+ if test_have_prereq XMLLINT
+ then
+ xmllint --noout "$@"
+ else
+ true
+ fi
+}
+
test_expect_success 'help text' '
test_expect_code 129 git maintenance -h 2>err &&
test_i18ngrep "usage: git maintenance <subcommand>" err &&
@@ -239,13 +252,15 @@ test_expect_success 'incremental-repack task' '
'
test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
+ test_config core.compression 0 &&
+
for i in $(test_seq 1 5)
do
test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big ||
return 1
done &&
git add big &&
- git commit -m "Add big file (1)" &&
+ git commit -qm "Add big file (1)" &&
# ensure any possible loose objects are in a pack-file
git maintenance run --task=loose-objects &&
@@ -257,7 +272,7 @@ test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
return 1
done &&
git add big &&
- git commit -m "Add big file (2)" &&
+ git commit -qm "Add big file (2)" &&
# ensure any possible loose objects are in a pack-file
git maintenance run --task=loose-objects &&
@@ -404,11 +419,23 @@ test_expect_success 'register and unregister' '
test_cmp before actual
'
+test_expect_success !MINGW 'register and unregister with regex metacharacters' '
+ META="a+b*c" &&
+ git init "$META" &&
+ git -C "$META" maintenance register &&
+ git config --get-all --show-origin maintenance.repo &&
+ git config --get-all --global --fixed-value \
+ maintenance.repo "$(pwd)/$META" &&
+ git -C "$META" maintenance unregister &&
+ test_must_fail git config --get-all --global --fixed-value \
+ maintenance.repo "$(pwd)/$META"
+'
+
test_expect_success 'start from empty cron table' '
- GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start &&
+ GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
# start registers the repo
- git config --get --global maintenance.repo "$(pwd)" &&
+ git config --get --global --fixed-value 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 &&
@@ -416,22 +443,121 @@ test_expect_success 'start from empty cron table' '
'
test_expect_success 'stop from existing schedule' '
- GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance stop &&
+ GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
# stop does not unregister the repo
- git config --get --global maintenance.repo "$(pwd)" &&
+ git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
# Operation is idempotent
- GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance stop &&
+ GIT_TEST_MAINT_SCHEDULER="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 &&
+ GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance start &&
grep "Important information!" cron.txt
'
+test_expect_success 'magic markers are correct' '
+ grep "GIT MAINTENANCE SCHEDULE" cron.txt >actual &&
+ cat >expect <<-\EOF &&
+ # BEGIN GIT MAINTENANCE SCHEDULE
+ # END GIT MAINTENANCE SCHEDULE
+ EOF
+ test_cmp actual expect
+'
+
+test_expect_success 'stop preserves surrounding schedule' '
+ echo "Crucial information!" >>cron.txt &&
+ GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt" git maintenance stop &&
+ grep "Important information!" cron.txt &&
+ grep "Crucial information!" cron.txt
+'
+
+test_expect_success 'start and stop macOS maintenance' '
+ # ensure $HOME can be compared against hook arguments on all platforms
+ pfx=$(cd "$HOME" && pwd) &&
+
+ write_script print-args <<-\EOF &&
+ echo $* | sed "s:gui/[0-9][0-9]*:gui/[UID]:" >>args
+ EOF
+
+ rm -f args &&
+ GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start &&
+
+ # start registers the repo
+ git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
+
+ ls "$HOME/Library/LaunchAgents" >actual &&
+ cat >expect <<-\EOF &&
+ org.git-scm.git.daily.plist
+ org.git-scm.git.hourly.plist
+ org.git-scm.git.weekly.plist
+ EOF
+ test_cmp expect actual &&
+
+ rm -f expect &&
+ for frequency in hourly daily weekly
+ do
+ PLIST="$pfx/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
+ test_xmllint "$PLIST" &&
+ grep schedule=$frequency "$PLIST" &&
+ echo "bootout gui/[UID] $PLIST" >>expect &&
+ echo "bootstrap gui/[UID] $PLIST" >>expect || return 1
+ done &&
+ test_cmp expect args &&
+
+ rm -f args &&
+ GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance stop &&
+
+ # stop does not unregister the repo
+ git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
+
+ printf "bootout gui/[UID] $pfx/Library/LaunchAgents/org.git-scm.git.%s.plist\n" \
+ hourly daily weekly >expect &&
+ test_cmp expect args &&
+ ls "$HOME/Library/LaunchAgents" >actual &&
+ test_line_count = 0 actual
+'
+
+test_expect_success 'start and stop Windows maintenance' '
+ write_script print-args <<-\EOF &&
+ echo $* >>args
+ while test $# -gt 0
+ do
+ case "$1" in
+ /xml) shift; xmlfile=$1; break ;;
+ *) shift ;;
+ esac
+ done
+ test -z "$xmlfile" || cp "$xmlfile" "$xmlfile.xml"
+ EOF
+
+ rm -f args &&
+ GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start &&
+
+ # start registers the repo
+ git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
+
+ for frequency in hourly daily weekly
+ do
+ grep "/create /tn Git Maintenance ($frequency) /f /xml" args &&
+ file=$(ls .git/schedule_${frequency}*.xml) &&
+ test_xmllint "$file" || return 1
+ done &&
+
+ rm -f args &&
+ GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop &&
+
+ # stop does not unregister the repo
+ git config --get --global --fixed-value maintenance.repo "$(pwd)" &&
+
+ printf "/delete /tn Git Maintenance (%s) /f\n" \
+ hourly daily weekly >expect &&
+ test_cmp expect args
+'
+
test_expect_success 'register preserves existing strategy' '
git config maintenance.strategy none &&
git maintenance register &&
@@ -441,4 +567,12 @@ test_expect_success 'register preserves existing strategy' '
test_config maintenance.strategy incremental
'
+test_expect_success 'fails when running outside of a repository' '
+ nongit test_must_fail git maintenance run &&
+ nongit test_must_fail git maintenance stop &&
+ nongit test_must_fail git maintenance start &&
+ nongit test_must_fail git maintenance register &&
+ nongit test_must_fail git maintenance unregister
+'
+
test_done