t / t3100-ls-tree-restrict.shon commit t0060: Fix tests on Windows (2718e85)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='git ls-tree test.
   7
   8This test runs git ls-tree with the following in a tree.
   9
  10    path0       - a file
  11    path1       - a symlink
  12    path2/foo   - a file in a directory
  13    path2/bazbo - a symlink in a directory
  14    path2/baz/b - a file in a directory in a directory
  15
  16The new path restriction code should do the right thing for path2 and
  17path2/baz.  Also path0/ should snow nothing.
  18'
  19. ./test-lib.sh
  20
  21test_expect_success \
  22    'setup' \
  23    'mkdir path2 path2/baz &&
  24     echo Hi >path0 &&
  25     if test_have_prereq SYMLINKS
  26     then
  27        ln -s path0 path1 &&
  28        ln -s ../path1 path2/bazbo
  29        make_expected () {
  30                cat >expected
  31        }
  32     else
  33        printf path0 > path1 &&
  34        printf ../path1 > path2/bazbo
  35        make_expected () {
  36                sed -e "s/120000 /100644 /" >expected
  37        }
  38     fi &&
  39     echo Lo >path2/foo &&
  40     echo Mi >path2/baz/b &&
  41     find path? \( -type f -o -type l \) -print |
  42     xargs git update-index --add &&
  43     tree=`git write-tree` &&
  44     echo $tree'
  45
  46_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  47_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
  48test_output () {
  49    sed -e "s/ $_x40    / X     /" <current >check
  50    test_cmp expected check
  51}
  52
  53test_expect_success \
  54    'ls-tree plain' \
  55    'git ls-tree $tree >current &&
  56     make_expected <<\EOF &&
  57100644 blob X   path0
  58120000 blob X   path1
  59040000 tree X   path2
  60EOF
  61     test_output'
  62
  63test_expect_success \
  64    'ls-tree recursive' \
  65    'git ls-tree -r $tree >current &&
  66     make_expected <<\EOF &&
  67100644 blob X   path0
  68120000 blob X   path1
  69100644 blob X   path2/baz/b
  70120000 blob X   path2/bazbo
  71100644 blob X   path2/foo
  72EOF
  73     test_output'
  74
  75test_expect_success \
  76    'ls-tree recursive with -t' \
  77    'git ls-tree -r -t $tree >current &&
  78     make_expected <<\EOF &&
  79100644 blob X   path0
  80120000 blob X   path1
  81040000 tree X   path2
  82040000 tree X   path2/baz
  83100644 blob X   path2/baz/b
  84120000 blob X   path2/bazbo
  85100644 blob X   path2/foo
  86EOF
  87     test_output'
  88
  89test_expect_success \
  90    'ls-tree recursive with -d' \
  91    'git ls-tree -r -d $tree >current &&
  92     make_expected <<\EOF &&
  93040000 tree X   path2
  94040000 tree X   path2/baz
  95EOF
  96     test_output'
  97
  98test_expect_success \
  99    'ls-tree filtered with path' \
 100    'git ls-tree $tree path >current &&
 101     make_expected <<\EOF &&
 102EOF
 103     test_output'
 104
 105
 106# it used to be path1 and then path0, but with pathspec semantics
 107# they are shown in canonical order.
 108test_expect_success \
 109    'ls-tree filtered with path1 path0' \
 110    'git ls-tree $tree path1 path0 >current &&
 111     make_expected <<\EOF &&
 112100644 blob X   path0
 113120000 blob X   path1
 114EOF
 115     test_output'
 116
 117test_expect_success \
 118    'ls-tree filtered with path0/' \
 119    'git ls-tree $tree path0/ >current &&
 120     make_expected <<\EOF &&
 121EOF
 122     test_output'
 123
 124# It used to show path2 and its immediate children but
 125# with pathspec semantics it shows only path2
 126test_expect_success \
 127    'ls-tree filtered with path2' \
 128    'git ls-tree $tree path2 >current &&
 129     make_expected <<\EOF &&
 130040000 tree X   path2
 131EOF
 132     test_output'
 133
 134# ... and path2/ shows the children.
 135test_expect_success \
 136    'ls-tree filtered with path2/' \
 137    'git ls-tree $tree path2/ >current &&
 138     make_expected <<\EOF &&
 139040000 tree X   path2/baz
 140120000 blob X   path2/bazbo
 141100644 blob X   path2/foo
 142EOF
 143     test_output'
 144
 145# The same change -- exact match does not show children of
 146# path2/baz
 147test_expect_success \
 148    'ls-tree filtered with path2/baz' \
 149    'git ls-tree $tree path2/baz >current &&
 150     make_expected <<\EOF &&
 151040000 tree X   path2/baz
 152EOF
 153     test_output'
 154
 155test_expect_success \
 156    'ls-tree filtered with path2/bak' \
 157    'git ls-tree $tree path2/bak >current &&
 158     make_expected <<\EOF &&
 159EOF
 160     test_output'
 161
 162test_expect_success \
 163    'ls-tree -t filtered with path2/bak' \
 164    'git ls-tree -t $tree path2/bak >current &&
 165     make_expected <<\EOF &&
 166040000 tree X   path2
 167EOF
 168     test_output'
 169
 170test_done