t / t1020-subdirectory.shon commit git-branch -D: make it work even when on a yet-to-be-born branch (67affd5)
   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 ok one ;;
  28        *) echo bad one; exit 1 ;;
  29        esac &&
  30        cd dir &&
  31        git-update-index --add two &&
  32        case "`git-ls-files`" in
  33        two) echo ok two ;;
  34        *) echo bad two; exit 1 ;;
  35        esac &&
  36        cd .. &&
  37        case "`git-ls-files`" in
  38        dir/two"$LF"one) echo ok both ;;
  39        *) echo bad; exit 1 ;;
  40        esac
  41'
  42
  43test_expect_success 'cat-file' '
  44        cd $HERE &&
  45        two=`git-ls-files -s dir/two` &&
  46        two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` &&
  47        echo "$two" &&
  48        git-cat-file -p "$two" >actual &&
  49        cmp dir/two actual &&
  50        cd dir &&
  51        git-cat-file -p "$two" >actual &&
  52        cmp two actual
  53'
  54rm -f actual dir/actual
  55
  56test_expect_success 'diff-files' '
  57        cd $HERE &&
  58        echo a >>one &&
  59        echo d >>dir/two &&
  60        case "`git-diff-files --name-only`" in
  61        dir/two"$LF"one) echo ok top ;;
  62        *) echo bad top; exit 1 ;;
  63        esac &&
  64        # diff should not omit leading paths
  65        cd dir &&
  66        case "`git-diff-files --name-only`" in
  67        dir/two"$LF"one) echo ok subdir ;;
  68        *) echo bad subdir; exit 1 ;;
  69        esac &&
  70        case "`git-diff-files --name-only .`" in
  71        dir/two) echo ok subdir limited ;;
  72        *) echo bad subdir limited; exit 1 ;;
  73        esac
  74'
  75
  76test_expect_success 'write-tree' '
  77        cd $HERE &&
  78        top=`git-write-tree` &&
  79        echo $top &&
  80        cd dir &&
  81        sub=`git-write-tree` &&
  82        echo $sub &&
  83        test "z$top" = "z$sub"
  84'
  85
  86test_expect_success 'checkout-index' '
  87        cd $HERE &&
  88        git-checkout-index -f -u one &&
  89        cmp one original.one &&
  90        cd dir &&
  91        git-checkout-index -f -u two &&
  92        cmp two ../original.two
  93'
  94
  95test_expect_success 'read-tree' '
  96        cd $HERE &&
  97        rm -f one dir/two &&
  98        tree=`git-write-tree` &&
  99        git-read-tree --reset -u "$tree" &&
 100        cmp one original.one &&
 101        cmp dir/two original.two &&
 102        cd dir &&
 103        rm -f two &&
 104        git-read-tree --reset -u "$tree" &&
 105        cmp two ../original.two &&
 106        cmp ../one ../original.one
 107'
 108
 109test_done