]>
Commit | Line | Data |
---|---|---|
9459aa77 NTND |
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 | ||
b2e5d75d | 8 | TEST_PASSES_SANITIZE_LEAK=true |
9459aa77 NTND |
9 | . ./test-lib.sh |
10 | ||
8fe5aedd JN |
11 | test_expect_success 'setup' ' |
12 | cat >test.patch <<-\EOF && | |
13 | diff --git a/test.txt b/test.txt | |
14 | new file mode 100644 | |
15 | --- /dev/null | |
16 | +++ b/test.txt | |
17 | @@ -0,0 +1 @@ | |
18 | +123 | |
19 | EOF | |
9459aa77 | 20 | |
8fe5aedd JN |
21 | test_create_repo "test" && |
22 | test_create_repo "test2" && | |
f7e87141 | 23 | git config --file=test2/.git/config core.repositoryformatversion 99 |
8fe5aedd | 24 | ' |
9459aa77 NTND |
25 | |
26 | test_expect_success 'gitdir selection on normal repos' ' | |
afb99327 PS |
27 | if test_have_prereq DEFAULT_REPO_FORMAT |
28 | then | |
29 | echo 0 | |
30 | else | |
31 | echo 1 | |
32 | fi >expect && | |
8fe5aedd | 33 | git config core.repositoryformatversion >actual && |
11ca4bec | 34 | git -C test config core.repositoryformatversion >actual2 && |
8fe5aedd JN |
35 | test_cmp expect actual && |
36 | test_cmp expect actual2 | |
37 | ' | |
9459aa77 | 38 | |
9459aa77 | 39 | test_expect_success 'gitdir selection on unsupported repo' ' |
8fe5aedd | 40 | # Make sure it would stop at test2, not trash |
17ae7f75 | 41 | test_expect_code 1 git -C test2 config core.repositoryformatversion |
8fe5aedd | 42 | ' |
9459aa77 NTND |
43 | |
44 | test_expect_success 'gitdir not required mode' ' | |
fd4ec4f2 | 45 | git apply --stat test.patch && |
11ca4bec JK |
46 | git -C test apply --stat ../test.patch && |
47 | git -C test2 apply --stat ../test.patch | |
18a82692 | 48 | ' |
9459aa77 | 49 | |
8fe5aedd JN |
50 | test_expect_success 'gitdir required mode' ' |
51 | git apply --check --index test.patch && | |
11ca4bec JK |
52 | git -C test apply --check --index ../test.patch && |
53 | test_must_fail git -C test2 apply --check --index ../test.patch | |
41ac414e | 54 | ' |
9459aa77 | 55 | |
00a09d57 JK |
56 | check_allow () { |
57 | git rev-parse --git-dir >actual && | |
58 | echo .git >expect && | |
59 | test_cmp expect actual | |
60 | } | |
61 | ||
62 | check_abort () { | |
63 | test_must_fail git rev-parse --git-dir | |
64 | } | |
65 | ||
66 | # avoid git-config, since it cannot be trusted to run | |
67 | # in a repository with a broken version | |
68 | mkconfig () { | |
69 | echo '[core]' && | |
70 | echo "repositoryformatversion = $1" && | |
71 | shift && | |
72 | ||
73 | if test $# -gt 0; then | |
74 | echo '[extensions]' && | |
75 | for i in "$@"; do | |
76 | echo "$i" | |
77 | done | |
78 | fi | |
79 | } | |
80 | ||
81 | while read outcome version extensions; do | |
82 | test_expect_success "$outcome version=$version $extensions" " | |
afb99327 PS |
83 | test_when_finished 'rm -rf extensions' && |
84 | git init extensions && | |
85 | ( | |
86 | cd extensions && | |
87 | mkconfig $version $extensions >.git/config && | |
88 | check_${outcome} | |
89 | ) | |
00a09d57 JK |
90 | " |
91 | done <<\EOF | |
92 | allow 0 | |
93 | allow 1 | |
94 | allow 1 noop | |
95 | abort 1 no-such-extension | |
96 | allow 0 no-such-extension | |
ec91ffca JK |
97 | allow 0 noop |
98 | abort 0 noop-v1 | |
99 | allow 1 noop-v1 | |
00a09d57 JK |
100 | EOF |
101 | ||
067fbd41 | 102 | test_expect_success 'precious-objects allowed' ' |
afb99327 PS |
103 | git config core.repositoryFormatVersion 1 && |
104 | git config extensions.preciousObjects 1 && | |
067fbd41 JK |
105 | check_allow |
106 | ' | |
107 | ||
108 | test_expect_success 'precious-objects blocks destructive repack' ' | |
109 | test_must_fail git repack -ad | |
110 | ' | |
111 | ||
112 | test_expect_success 'other repacks are OK' ' | |
113 | test_commit foo && | |
114 | git repack | |
115 | ' | |
116 | ||
117 | test_expect_success 'precious-objects blocks prune' ' | |
118 | test_must_fail git prune | |
119 | ' | |
120 | ||
121 | test_expect_success 'gc runs without complaint' ' | |
122 | git gc | |
123 | ' | |
124 | ||
9459aa77 | 125 | test_done |