]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1302-repo-version.sh
Merge branch 'jc/bisect-doc' into maint-2.43
[thirdparty/git.git] / t / t1302-repo-version.sh
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 test_expect_success 'setup' '
12 test_oid_cache <<-\EOF &&
13 version sha1:0
14 version sha256:1
15 EOF
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
24
25 test_create_repo "test" &&
26 test_create_repo "test2" &&
27 git config --file=test2/.git/config core.repositoryformatversion 99
28 '
29
30 test_expect_success 'gitdir selection on normal repos' '
31 test_oid version >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 mkconfig $version $extensions >.git/config &&
83 check_${outcome}
84 "
85 done <<\EOF
86 allow 0
87 allow 1
88 allow 1 noop
89 abort 1 no-such-extension
90 allow 0 no-such-extension
91 allow 0 noop
92 abort 0 noop-v1
93 allow 1 noop-v1
94 EOF
95
96 test_expect_success 'precious-objects allowed' '
97 mkconfig 1 preciousObjects >.git/config &&
98 check_allow
99 '
100
101 test_expect_success 'precious-objects blocks destructive repack' '
102 test_must_fail git repack -ad
103 '
104
105 test_expect_success 'other repacks are OK' '
106 test_commit foo &&
107 git repack
108 '
109
110 test_expect_success 'precious-objects blocks prune' '
111 test_must_fail git prune
112 '
113
114 test_expect_success 'gc runs without complaint' '
115 git gc
116 '
117
118 test_done