t / t1302-repo-version.shon commit t1302: use "git -C" (11ca4be)
   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        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
  31'
  32
  33test_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
  38'
  39
  40test_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
  44'
  45
  46test_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
  50'
  51
  52check_allow () {
  53        git rev-parse --git-dir >actual &&
  54        echo .git >expect &&
  55        test_cmp expect actual
  56}
  57
  58check_abort () {
  59        test_must_fail git rev-parse --git-dir
  60}
  61
  62# avoid git-config, since it cannot be trusted to run
  63# in a repository with a broken version
  64mkconfig () {
  65        echo '[core]' &&
  66        echo "repositoryformatversion = $1" &&
  67        shift &&
  68
  69        if test $# -gt 0; then
  70                echo '[extensions]' &&
  71                for i in "$@"; do
  72                        echo "$i"
  73                done
  74        fi
  75}
  76
  77while read outcome version extensions; do
  78        test_expect_success "$outcome version=$version $extensions" "
  79                mkconfig $version $extensions >.git/config &&
  80                check_${outcome}
  81        "
  82done <<\EOF
  83allow 0
  84allow 1
  85allow 1 noop
  86abort 1 no-such-extension
  87allow 0 no-such-extension
  88EOF
  89
  90test_expect_success 'precious-objects allowed' '
  91        mkconfig 1 preciousObjects >.git/config &&
  92        check_allow
  93'
  94
  95test_expect_success 'precious-objects blocks destructive repack' '
  96        test_must_fail git repack -ad
  97'
  98
  99test_expect_success 'other repacks are OK' '
 100        test_commit foo &&
 101        git repack
 102'
 103
 104test_expect_success 'precious-objects blocks prune' '
 105        test_must_fail git prune
 106'
 107
 108test_expect_success 'gc runs without complaint' '
 109        git gc
 110'
 111
 112test_done