interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t1302-repo-version.sh

124 lines · 2637 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2007 Nguyễn Thái Ngọc Duy
4#
5
6test_description='Test repository version check'
7
8. ./test-lib.sh
9
10test_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
25test_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
38test_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
43test_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
49test_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
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 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 "
90done <<\EOF
91allow 0
92allow 1
93allow 1 noop
94abort 1 no-such-extension
95allow 0 no-such-extension
96allow 0 noop
97abort 0 noop-v1
98allow 1 noop-v1
99EOF
100
101test_expect_success 'precious-objects allowed' '
102 git config core.repositoryFormatVersion 1 &&
103 git config extensions.preciousObjects 1 &&
104 check_allow
105'
106
107test_expect_success 'precious-objects blocks destructive repack' '
108 test_must_fail git repack -ad
109'
110
111test_expect_success 'other repacks are OK' '
112 test_commit foo &&
113 git repack
114'
115
116test_expect_success 'precious-objects blocks prune' '
117 test_must_fail git prune
118'
119
120test_expect_success 'gc runs without complaint' '
121 git gc
122'
123
124test_done