Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Nguyễn Thái Ngọc Duy |
| 4 | # |
| 5 | |
| 6 | test_description='Test repository version check' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 10 | test_expect_success 'setup' ' |
| 11 | cat >test.patch <<-\EOF && |
| 12 | diff --git a/test.txt b/test.txt |
| 13 | new file mode 100644 |
| 14 | --- /dev/null |
| 15 | +++ b/test.txt |
| 16 | @@ -0,0 +1 @@ |
| 17 | +123 |
| 18 | EOF |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 19 | |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 20 | test_create_repo "test" && |
| 21 | test_create_repo "test2" && |
Jeff King | f7e8714 | 2014-03-20 19:17:01 -0400 | [diff] [blame] | 22 | git config --file=test2/.git/config core.repositoryformatversion 99 |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 23 | ' |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 24 | |
| 25 | test_expect_success 'gitdir selection on normal repos' ' |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 26 | echo 0 >expect && |
| 27 | git config core.repositoryformatversion >actual && |
Jeff King | 11ca4be | 2016-09-12 20:24:00 -0700 | [diff] [blame] | 28 | git -C test config core.repositoryformatversion >actual2 && |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 29 | test_cmp expect actual && |
| 30 | test_cmp expect actual2 |
| 31 | ' |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 32 | |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 33 | test_expect_success 'gitdir selection on unsupported repo' ' |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 34 | # Make sure it would stop at test2, not trash |
Jeff King | b9605bc | 2016-09-12 20:24:15 -0700 | [diff] [blame] | 35 | test_expect_code 1 git -C test2 config core.repositoryformatversion >actual |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 36 | ' |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 37 | |
| 38 | test_expect_success 'gitdir not required mode' ' |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 39 | git apply --stat test.patch && |
Jeff King | 11ca4be | 2016-09-12 20:24:00 -0700 | [diff] [blame] | 40 | git -C test apply --stat ../test.patch && |
| 41 | git -C test2 apply --stat ../test.patch |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 42 | ' |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 43 | |
Jonathan Nieder | 8fe5aed | 2010-09-06 20:52:27 -0500 | [diff] [blame] | 44 | test_expect_success 'gitdir required mode' ' |
| 45 | git apply --check --index test.patch && |
Jeff King | 11ca4be | 2016-09-12 20:24:00 -0700 | [diff] [blame] | 46 | git -C test apply --check --index ../test.patch && |
| 47 | test_must_fail git -C test2 apply --check --index ../test.patch |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 48 | ' |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 49 | |
Jeff King | 00a09d5 | 2015-06-23 06:53:58 -0400 | [diff] [blame] | 50 | check_allow () { |
| 51 | git rev-parse --git-dir >actual && |
| 52 | echo .git >expect && |
| 53 | test_cmp expect actual |
| 54 | } |
| 55 | |
| 56 | check_abort () { |
| 57 | test_must_fail git rev-parse --git-dir |
| 58 | } |
| 59 | |
| 60 | # avoid git-config, since it cannot be trusted to run |
| 61 | # in a repository with a broken version |
| 62 | mkconfig () { |
| 63 | echo '[core]' && |
| 64 | echo "repositoryformatversion = $1" && |
| 65 | shift && |
| 66 | |
| 67 | if test $# -gt 0; then |
| 68 | echo '[extensions]' && |
| 69 | for i in "$@"; do |
| 70 | echo "$i" |
| 71 | done |
| 72 | fi |
| 73 | } |
| 74 | |
| 75 | while read outcome version extensions; do |
| 76 | test_expect_success "$outcome version=$version $extensions" " |
| 77 | mkconfig $version $extensions >.git/config && |
| 78 | check_${outcome} |
| 79 | " |
| 80 | done <<\EOF |
| 81 | allow 0 |
| 82 | allow 1 |
| 83 | allow 1 noop |
| 84 | abort 1 no-such-extension |
| 85 | allow 0 no-such-extension |
| 86 | EOF |
| 87 | |
Jeff King | 067fbd4 | 2015-06-23 06:54:11 -0400 | [diff] [blame] | 88 | test_expect_success 'precious-objects allowed' ' |
| 89 | mkconfig 1 preciousObjects >.git/config && |
| 90 | check_allow |
| 91 | ' |
| 92 | |
| 93 | test_expect_success 'precious-objects blocks destructive repack' ' |
| 94 | test_must_fail git repack -ad |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'other repacks are OK' ' |
| 98 | test_commit foo && |
| 99 | git repack |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'precious-objects blocks prune' ' |
| 103 | test_must_fail git prune |
| 104 | ' |
| 105 | |
| 106 | test_expect_success 'gc runs without complaint' ' |
| 107 | git gc |
| 108 | ' |
| 109 | |
Nguyễn Thái Ngọc Duy | 9459aa7 | 2007-12-05 20:33:32 +0700 | [diff] [blame] | 110 | test_done |