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