]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1302-repo-version.sh
The third batch
[thirdparty/git.git] / t / t1302-repo-version.sh
CommitLineData
9459aa77
NTND
1#!/bin/sh
2#
3# Copyright (c) 2007 Nguyễn Thái Ngọc Duy
4#
5
6test_description='Test repository version check'
7
b2e5d75d 8TEST_PASSES_SANITIZE_LEAK=true
9459aa77
NTND
9. ./test-lib.sh
10
8fe5aedd
JN
11test_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
26test_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 39test_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
44test_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
50test_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
56check_allow () {
57 git rev-parse --git-dir >actual &&
58 echo .git >expect &&
59 test_cmp expect actual
60}
61
62check_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
68mkconfig () {
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
81while 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 "
91done <<\EOF
92allow 0
93allow 1
94allow 1 noop
95abort 1 no-such-extension
96allow 0 no-such-extension
ec91ffca
JK
97allow 0 noop
98abort 0 noop-v1
99allow 1 noop-v1
00a09d57
JK
100EOF
101
067fbd41 102test_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
108test_expect_success 'precious-objects blocks destructive repack' '
109 test_must_fail git repack -ad
110'
111
112test_expect_success 'other repacks are OK' '
113 test_commit foo &&
114 git repack
115'
116
117test_expect_success 'precious-objects blocks prune' '
118 test_must_fail git prune
119'
120
121test_expect_success 'gc runs without complaint' '
122 git gc
123'
124
9459aa77 125test_done