Merge branch 'es/worktree-repair-copied' into cw/worktrees-relative
[git/gitster.git] / t / t1302-repo-version.sh
blob42caa0d2978b58755d43b3361589c6e7691c34db
1 #!/bin/sh
3 # Copyright (c) 2007 Nguyễn Thái Ngọc Duy
6 test_description='Test repository version check'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_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
21 test_create_repo "test" &&
22 test_create_repo "test2" &&
23 git config --file=test2/.git/config core.repositoryformatversion 99
26 test_expect_success 'gitdir selection on normal repos' '
27 if test_have_prereq DEFAULT_REPO_FORMAT
28 then
29 echo 0
30 else
31 echo 1
32 fi >expect &&
33 git config core.repositoryformatversion >actual &&
34 git -C test config core.repositoryformatversion >actual2 &&
35 test_cmp expect actual &&
36 test_cmp expect actual2
39 test_expect_success 'gitdir selection on unsupported repo' '
40 # Make sure it would stop at test2, not trash
41 test_expect_code 1 git -C test2 config core.repositoryformatversion
44 test_expect_success 'gitdir not required mode' '
45 git apply --stat test.patch &&
46 git -C test apply --stat ../test.patch &&
47 git -C test2 apply --stat ../test.patch
50 test_expect_success 'gitdir required mode' '
51 git apply --check --index test.patch &&
52 git -C test apply --check --index ../test.patch &&
53 test_must_fail git -C test2 apply --check --index ../test.patch
56 check_allow () {
57 git rev-parse --git-dir >actual &&
58 echo .git >expect &&
59 test_cmp expect actual
62 check_abort () {
63 test_must_fail git rev-parse --git-dir
66 # avoid git-config, since it cannot be trusted to run
67 # in a repository with a broken version
68 mkconfig () {
69 echo '[core]' &&
70 echo "repositoryformatversion = $1" &&
71 shift &&
73 if test $# -gt 0; then
74 echo '[extensions]' &&
75 for i in "$@"; do
76 echo "$i"
77 done
81 while read outcome version extensions; do
82 test_expect_success "$outcome version=$version $extensions" "
83 test_when_finished 'rm -rf extensions' &&
84 git init extensions &&
86 cd extensions &&
87 mkconfig $version $extensions >.git/config &&
88 check_${outcome}
91 done <<\EOF
92 allow 0
93 allow 1
94 allow 1 noop
95 abort 1 no-such-extension
96 allow 0 no-such-extension
97 allow 0 noop
98 abort 0 noop-v1
99 allow 1 noop-v1
102 test_expect_success 'precious-objects allowed' '
103 git config core.repositoryFormatVersion 1 &&
104 git config extensions.preciousObjects 1 &&
105 check_allow
108 test_expect_success 'precious-objects blocks destructive repack' '
109 test_must_fail git repack -ad
112 test_expect_success 'other repacks are OK' '
113 test_commit foo &&
114 git repack
117 test_expect_success 'precious-objects blocks prune' '
118 test_must_fail git prune
121 test_expect_success 'gc runs without complaint' '
122 git gc
125 test_done