t / t3100-ls-tree-restrict.shon commit gitweb: Fix bug in insert_file() subroutine (4586864)
   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     ln -s path0 path1 &&
  26     echo Lo >path2/foo &&
  27     ln -s ../path1 path2/bazbo &&
  28     echo Mi >path2/baz/b &&
  29     find path? \( -type f -o -type l \) -print |
  30     xargs git update-index --add &&
  31     tree=`git write-tree` &&
  32     echo $tree'
  33
  34_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  35_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
  36test_output () {
  37    sed -e "s/ $_x40    / X     /" <current >check
  38    test_cmp expected check
  39}
  40
  41test_expect_success \
  42    'ls-tree plain' \
  43    'git ls-tree $tree >current &&
  44     cat >expected <<\EOF &&
  45100644 blob X   path0
  46120000 blob X   path1
  47040000 tree X   path2
  48EOF
  49     test_output'
  50
  51test_expect_success \
  52    'ls-tree recursive' \
  53    'git ls-tree -r $tree >current &&
  54     cat >expected <<\EOF &&
  55100644 blob X   path0
  56120000 blob X   path1
  57100644 blob X   path2/baz/b
  58120000 blob X   path2/bazbo
  59100644 blob X   path2/foo
  60EOF
  61     test_output'
  62
  63test_expect_success \
  64    'ls-tree recursive with -t' \
  65    'git ls-tree -r -t $tree >current &&
  66     cat >expected <<\EOF &&
  67100644 blob X   path0
  68120000 blob X   path1
  69040000 tree X   path2
  70040000 tree X   path2/baz
  71100644 blob X   path2/baz/b
  72120000 blob X   path2/bazbo
  73100644 blob X   path2/foo
  74EOF
  75     test_output'
  76
  77test_expect_success \
  78    'ls-tree recursive with -d' \
  79    'git ls-tree -r -d $tree >current &&
  80     cat >expected <<\EOF &&
  81040000 tree X   path2
  82040000 tree X   path2/baz
  83EOF
  84     test_output'
  85
  86test_expect_success \
  87    'ls-tree filtered with path' \
  88    'git ls-tree $tree path >current &&
  89     cat >expected <<\EOF &&
  90EOF
  91     test_output'
  92
  93
  94# it used to be path1 and then path0, but with pathspec semantics
  95# they are shown in canonical order.
  96test_expect_success \
  97    'ls-tree filtered with path1 path0' \
  98    'git ls-tree $tree path1 path0 >current &&
  99     cat >expected <<\EOF &&
 100100644 blob X   path0
 101120000 blob X   path1
 102EOF
 103     test_output'
 104
 105test_expect_success \
 106    'ls-tree filtered with path0/' \
 107    'git ls-tree $tree path0/ >current &&
 108     cat >expected <<\EOF &&
 109EOF
 110     test_output'
 111
 112# It used to show path2 and its immediate children but
 113# with pathspec semantics it shows only path2
 114test_expect_success \
 115    'ls-tree filtered with path2' \
 116    'git ls-tree $tree path2 >current &&
 117     cat >expected <<\EOF &&
 118040000 tree X   path2
 119EOF
 120     test_output'
 121
 122# ... and path2/ shows the children.
 123test_expect_success \
 124    'ls-tree filtered with path2/' \
 125    'git ls-tree $tree path2/ >current &&
 126     cat >expected <<\EOF &&
 127040000 tree X   path2/baz
 128120000 blob X   path2/bazbo
 129100644 blob X   path2/foo
 130EOF
 131     test_output'
 132
 133# The same change -- exact match does not show children of
 134# path2/baz
 135test_expect_success \
 136    'ls-tree filtered with path2/baz' \
 137    'git ls-tree $tree path2/baz >current &&
 138     cat >expected <<\EOF &&
 139040000 tree X   path2/baz
 140EOF
 141     test_output'
 142
 143test_expect_success \
 144    'ls-tree filtered with path2/bak' \
 145    'git ls-tree $tree path2/bak >current &&
 146     cat >expected <<\EOF &&
 147EOF
 148     test_output'
 149
 150test_expect_success \
 151    'ls-tree -t filtered with path2/bak' \
 152    'git ls-tree -t $tree path2/bak >current &&
 153     cat >expected <<\EOF &&
 154040000 tree X   path2
 155EOF
 156     test_output'
 157
 158test_done