t / t0002-gitfile.shon commit wildmatch: adjust "**" behavior (40bbee0)
   1#!/bin/sh
   2
   3test_description='.git file
   4
   5Verify that plumbing commands work when .git is a file
   6'
   7. ./test-lib.sh
   8
   9objpath() {
  10    echo "$1" | sed -e 's|\(..\)|\1/|'
  11}
  12
  13objck() {
  14        p=$(objpath "$1")
  15        if test ! -f "$REAL/objects/$p"
  16        then
  17                echo "Object not found: $REAL/objects/$p"
  18                false
  19        fi
  20}
  21
  22
  23test_expect_success 'initial setup' '
  24        REAL="$(pwd)/.real" &&
  25        mv .git "$REAL"
  26'
  27
  28test_expect_success 'bad setup: invalid .git file format' '
  29        echo "gitdir $REAL" >.git &&
  30        if git rev-parse 2>.err
  31        then
  32                echo "git rev-parse accepted an invalid .git file"
  33                false
  34        fi &&
  35        if ! grep "Invalid gitfile format" .err
  36        then
  37                echo "git rev-parse returned wrong error"
  38                false
  39        fi
  40'
  41
  42test_expect_success 'bad setup: invalid .git file path' '
  43        echo "gitdir: $REAL.not" >.git &&
  44        if git rev-parse 2>.err
  45        then
  46                echo "git rev-parse accepted an invalid .git file path"
  47                false
  48        fi &&
  49        if ! grep "Not a git repository" .err
  50        then
  51                echo "git rev-parse returned wrong error"
  52                false
  53        fi
  54'
  55
  56test_expect_success 'final setup + check rev-parse --git-dir' '
  57        echo "gitdir: $REAL" >.git &&
  58        test "$REAL" = "$(git rev-parse --git-dir)"
  59'
  60
  61test_expect_success 'check hash-object' '
  62        echo "foo" >bar &&
  63        SHA=$(cat bar | git hash-object -w --stdin) &&
  64        objck $SHA
  65'
  66
  67test_expect_success 'check cat-file' '
  68        git cat-file blob $SHA >actual &&
  69        test_cmp bar actual
  70'
  71
  72test_expect_success 'check update-index' '
  73        if test -f "$REAL/index"
  74        then
  75                echo "Hmm, $REAL/index exists?"
  76                false
  77        fi &&
  78        rm -f "$REAL/objects/$(objpath $SHA)" &&
  79        git update-index --add bar &&
  80        if ! test -f "$REAL/index"
  81        then
  82                echo "$REAL/index not found"
  83                false
  84        fi &&
  85        objck $SHA
  86'
  87
  88test_expect_success 'check write-tree' '
  89        SHA=$(git write-tree) &&
  90        objck $SHA
  91'
  92
  93test_expect_success 'check commit-tree' '
  94        SHA=$(echo "commit bar" | git commit-tree $SHA) &&
  95        objck $SHA
  96'
  97
  98test_expect_success 'check rev-list' '
  99        echo $SHA >"$REAL/HEAD" &&
 100        test "$SHA" = "$(git rev-list HEAD)"
 101'
 102
 103test_done