t1302: use "git -C"
[git/debian.git] / t / t1302-repo-version.sh
blobf859809b3613dc8fa67f1acb1f8127ee9bbd4391
1 #!/bin/sh
3 # Copyright (c) 2007 Nguyễn Thái Ngọc Duy
6 test_description='Test repository version check'
8 . ./test-lib.sh
10 test_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
20 test_create_repo "test" &&
21 test_create_repo "test2" &&
22 git config --file=test2/.git/config core.repositoryformatversion 99
25 test_expect_success 'gitdir selection on normal repos' '
26 echo 0 >expect &&
27 git config core.repositoryformatversion >actual &&
28 git -C test config core.repositoryformatversion >actual2 &&
29 test_cmp expect actual &&
30 test_cmp expect actual2
33 test_expect_success 'gitdir selection on unsupported repo' '
34 # Make sure it would stop at test2, not trash
35 echo 99 >expect &&
36 git -C test2 config core.repositoryformatversion >actual &&
37 test_cmp expect actual
40 test_expect_success 'gitdir not required mode' '
41 git apply --stat test.patch &&
42 git -C test apply --stat ../test.patch &&
43 git -C test2 apply --stat ../test.patch
46 test_expect_success 'gitdir required mode' '
47 git apply --check --index test.patch &&
48 git -C test apply --check --index ../test.patch &&
49 test_must_fail git -C test2 apply --check --index ../test.patch
52 check_allow () {
53 git rev-parse --git-dir >actual &&
54 echo .git >expect &&
55 test_cmp expect actual
58 check_abort () {
59 test_must_fail git rev-parse --git-dir
62 # avoid git-config, since it cannot be trusted to run
63 # in a repository with a broken version
64 mkconfig () {
65 echo '[core]' &&
66 echo "repositoryformatversion = $1" &&
67 shift &&
69 if test $# -gt 0; then
70 echo '[extensions]' &&
71 for i in "$@"; do
72 echo "$i"
73 done
77 while read outcome version extensions; do
78 test_expect_success "$outcome version=$version $extensions" "
79 mkconfig $version $extensions >.git/config &&
80 check_${outcome}
82 done <<\EOF
83 allow 0
84 allow 1
85 allow 1 noop
86 abort 1 no-such-extension
87 allow 0 no-such-extension
88 EOF
90 test_expect_success 'precious-objects allowed' '
91 mkconfig 1 preciousObjects >.git/config &&
92 check_allow
95 test_expect_success 'precious-objects blocks destructive repack' '
96 test_must_fail git repack -ad
99 test_expect_success 'other repacks are OK' '
100 test_commit foo &&
101 git repack
104 test_expect_success 'precious-objects blocks prune' '
105 test_must_fail git prune
108 test_expect_success 'gc runs without complaint' '
109 git gc
112 test_done