Merge branch 'dt/fsck-verify-pack-error'
[git/debian.git] / t / t1302-repo-version.sh
blob9bcd34969f56038d3933471bc32641a277d413ba
1 #!/bin/sh
3 # Copyright (c) 2007 Nguyễn Thái Ngọc Duy
6 test_description='Test repository version check'
8 . ./test-lib.sh
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
20 test_create_repo "test" &&
21 test_create_repo "test2" &&
22 git config --file=test2/.git/config core.repositoryformatversion 99
25 test_expect_success 'gitdir selection on normal repos' '
26 echo 0 >expect &&
27 git config core.repositoryformatversion >actual &&
29 cd test &&
30 git config core.repositoryformatversion >../actual2
31 ) &&
32 test_cmp expect actual &&
33 test_cmp expect actual2
36 test_expect_success 'gitdir selection on unsupported repo' '
37 # Make sure it would stop at test2, not trash
38 echo 99 >expect &&
40 cd test2 &&
41 git config core.repositoryformatversion >../actual
42 ) &&
43 test_cmp expect actual
46 test_expect_success 'gitdir not required mode' '
47 git apply --stat test.patch &&
49 cd test &&
50 git apply --stat ../test.patch
51 ) &&
53 cd test2 &&
54 git apply --stat ../test.patch
58 test_expect_success 'gitdir required mode' '
59 git apply --check --index test.patch &&
61 cd test &&
62 git apply --check --index ../test.patch
63 ) &&
65 cd test2 &&
66 test_must_fail git apply --check --index ../test.patch
70 check_allow () {
71 git rev-parse --git-dir >actual &&
72 echo .git >expect &&
73 test_cmp expect actual
76 check_abort () {
77 test_must_fail git rev-parse --git-dir
80 # avoid git-config, since it cannot be trusted to run
81 # in a repository with a broken version
82 mkconfig () {
83 echo '[core]' &&
84 echo "repositoryformatversion = $1" &&
85 shift &&
87 if test $# -gt 0; then
88 echo '[extensions]' &&
89 for i in "$@"; do
90 echo "$i"
91 done
95 while read outcome version extensions; do
96 test_expect_success "$outcome version=$version $extensions" "
97 mkconfig $version $extensions >.git/config &&
98 check_${outcome}
100 done <<\EOF
101 allow 0
102 allow 1
103 allow 1 noop
104 abort 1 no-such-extension
105 allow 0 no-such-extension
108 test_expect_success 'precious-objects allowed' '
109 mkconfig 1 preciousObjects >.git/config &&
110 check_allow
113 test_expect_success 'precious-objects blocks destructive repack' '
114 test_must_fail git repack -ad
117 test_expect_success 'other repacks are OK' '
118 test_commit foo &&
119 git repack
122 test_expect_success 'precious-objects blocks prune' '
123 test_must_fail git prune
126 test_expect_success 'gc runs without complaint' '
127 git gc
130 test_done