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