0d0da17eb8098b64c9165c8fad29baa8be17da43
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='Try various core-level commands in subdirectory.
   7'
   8
   9. ./test-lib.sh
  10
  11test_expect_success setup '
  12        long="a b c d e f g h i j k l m n o p q r s t u v w x y z" &&
  13        for c in $long; do echo $c; done >one &&
  14        mkdir dir &&
  15        for c in x y z $long a b c; do echo $c; done >dir/two &&
  16        cp one original.one &&
  17        cp dir/two original.two
  18'
  19HERE=`pwd`
  20LF='
  21'
  22
  23test_expect_success 'update-index and ls-files' '
  24        cd "$HERE" &&
  25        git update-index --add one &&
  26        case "`git ls-files`" in
  27        one) echo pass one ;;
  28        *) echo bad one; exit 1 ;;
  29        esac &&
  30        (
  31                cd dir &&
  32                git update-index --add two &&
  33                case "`git ls-files`" in
  34                two) echo pass two ;;
  35                *) echo bad two; exit 1 ;;
  36                esac
  37        ) &&
  38        case "`git ls-files`" in
  39        dir/two"$LF"one) echo pass both ;;
  40        *) echo bad; exit 1 ;;
  41        esac
  42'
  43
  44test_expect_success 'cat-file' '
  45        cd "$HERE" &&
  46        two=`git ls-files -s dir/two` &&
  47        two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
  48        echo "$two" &&
  49        git cat-file -p "$two" >actual &&
  50        cmp dir/two actual &&
  51        cd dir &&
  52        git cat-file -p "$two" >actual &&
  53        cmp two actual
  54'
  55rm -f actual dir/actual
  56
  57test_expect_success 'diff-files' '
  58        cd "$HERE" &&
  59        echo a >>one &&
  60        echo d >>dir/two &&
  61        case "`git diff-files --name-only`" in
  62        dir/two"$LF"one) echo pass top ;;
  63        *) echo bad top; exit 1 ;;
  64        esac &&
  65        # diff should not omit leading paths
  66        cd dir &&
  67        case "`git diff-files --name-only`" in
  68        dir/two"$LF"one) echo pass subdir ;;
  69        *) echo bad subdir; exit 1 ;;
  70        esac &&
  71        case "`git diff-files --name-only .`" in
  72        dir/two) echo pass subdir limited ;;
  73        *) echo bad subdir limited; exit 1 ;;
  74        esac
  75'
  76
  77test_expect_success 'write-tree' '
  78        cd "$HERE" &&
  79        top=`git write-tree` &&
  80        echo $top &&
  81        cd dir &&
  82        sub=`git write-tree` &&
  83        echo $sub &&
  84        test "z$top" = "z$sub"
  85'
  86
  87test_expect_success 'checkout-index' '
  88        cd "$HERE" &&
  89        git checkout-index -f -u one &&
  90        cmp one original.one &&
  91        cd dir &&
  92        git checkout-index -f -u two &&
  93        cmp two ../original.two
  94'
  95
  96test_expect_success 'read-tree' '
  97        cd "$HERE" &&
  98        rm -f one dir/two &&
  99        tree=`git write-tree` &&
 100        git read-tree --reset -u "$tree" &&
 101        cmp one original.one &&
 102        cmp dir/two original.two &&
 103        cd dir &&
 104        rm -f two &&
 105        git read-tree --reset -u "$tree" &&
 106        cmp two ../original.two &&
 107        cmp ../one ../original.one
 108'
 109
 110test_expect_success 'no file/rev ambiguity check inside .git' '
 111        cd "$HERE" &&
 112        git commit -a -m 1 &&
 113        cd "$HERE"/.git &&
 114        git show -s HEAD
 115'
 116
 117test_expect_success 'no file/rev ambiguity check inside a bare repo' '
 118        cd "$HERE" &&
 119        git clone -s --bare .git foo.git &&
 120        cd foo.git && GIT_DIR=. git show -s HEAD
 121'
 122
 123# This still does not work as it should...
 124: test_expect_success 'no file/rev ambiguity check inside a bare repo' '
 125        cd "$HERE" &&
 126        git clone -s --bare .git foo.git &&
 127        cd foo.git && git show -s HEAD
 128'
 129
 130test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
 131        cd "$HERE" &&
 132        rm -fr foo.git &&
 133        git clone -s .git another &&
 134        ln -s another yetanother &&
 135        cd yetanother/.git &&
 136        git show -s HEAD
 137'
 138
 139test_done