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 test_oid_cache <<-\EOF && 12 version sha1:0 13 version sha256:1 14 EOF 15 cat >test.patch <<-\EOF && 16 diff --git a/test.txt b/test.txt 17 new file mode 100644 18 --- /dev/null 19 +++ b/test.txt 20 @@ -0,0 +1 @@ 21 +123 22 EOF 23 24 test_create_repo "test" && 25 test_create_repo "test2" && 26 git config --file=test2/.git/config core.repositoryformatversion 99 27' 28 29test_expect_success 'gitdir selection on normal repos' ' 30 echo $(test_oid version) >expect && 31 git config core.repositoryformatversion >actual && 32 git -C test config core.repositoryformatversion >actual2 && 33 test_cmp expect actual && 34 test_cmp expect actual2 35' 36 37test_expect_success 'gitdir selection on unsupported repo' ' 38 # Make sure it would stop at test2, not trash 39 test_expect_code 1 git -C test2 config core.repositoryformatversion >actual 40' 41 42test_expect_success 'gitdir not required mode' ' 43 git apply --stat test.patch && 44 git -C test apply --stat ../test.patch && 45 git -C test2 apply --stat ../test.patch 46' 47 48test_expect_success 'gitdir required mode' ' 49 git apply --check --index test.patch && 50 git -C test apply --check --index ../test.patch && 51 test_must_fail git -C test2 apply --check --index ../test.patch 52' 53 54check_allow () { 55 git rev-parse --git-dir >actual && 56 echo .git >expect && 57 test_cmp expect actual 58} 59 60check_abort () { 61 test_must_fail git rev-parse --git-dir 62} 63 64# avoid git-config, since it cannot be trusted to run 65# in a repository with a broken version 66mkconfig () { 67 echo '[core]' && 68 echo "repositoryformatversion = $1" && 69 shift && 70 71 if test $# -gt 0; then 72 echo '[extensions]' && 73 for i in "$@"; do 74 echo "$i" 75 done 76 fi 77} 78 79while read outcome version extensions; do 80 test_expect_success "$outcome version=$version $extensions" " 81 mkconfig $version $extensions >.git/config && 82 check_${outcome} 83 " 84done <<\EOF 85allow 0 86allow 1 87allow 1 noop 88abort 1 no-such-extension 89allow 0 no-such-extension 90allow 0 noop 91abort 0 noop-v1 92allow 1 noop-v1 93EOF 94 95test_expect_success 'precious-objects allowed' ' 96 mkconfig 1 preciousObjects >.git/config && 97 check_allow 98' 99 100test_expect_success 'precious-objects blocks destructive repack' ' 101 test_must_fail git repack -ad 102' 103 104test_expect_success 'other repacks are OK' ' 105 test_commit foo && 106 git repack 107' 108 109test_expect_success 'precious-objects blocks prune' ' 110 test_must_fail git prune 111' 112 113test_expect_success 'gc runs without complaint' ' 114 git gc 115' 116 117test_done 118