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