t / t3100-ls-tree-restrict.shon commit notes remove: allow removing more than one (c3ab1a8)
   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
  46test_output () {
  47    sed -e "s/ $_x40    / X     /" <current >check
  48    test_cmp expected check
  49}
  50
  51test_expect_success \
  52    'ls-tree plain' \
  53    'git ls-tree $tree >current &&
  54     make_expected <<\EOF &&
  55100644 blob X   path0
  56120000 blob X   path1
  57040000 tree X   path2
  58EOF
  59     test_output'
  60
  61test_expect_success \
  62    'ls-tree recursive' \
  63    'git ls-tree -r $tree >current &&
  64     make_expected <<\EOF &&
  65100644 blob X   path0
  66120000 blob X   path1
  67100644 blob X   path2/baz/b
  68120000 blob X   path2/bazbo
  69100644 blob X   path2/foo
  70EOF
  71     test_output'
  72
  73test_expect_success \
  74    'ls-tree recursive with -t' \
  75    'git ls-tree -r -t $tree >current &&
  76     make_expected <<\EOF &&
  77100644 blob X   path0
  78120000 blob X   path1
  79040000 tree X   path2
  80040000 tree X   path2/baz
  81100644 blob X   path2/baz/b
  82120000 blob X   path2/bazbo
  83100644 blob X   path2/foo
  84EOF
  85     test_output'
  86
  87test_expect_success \
  88    'ls-tree recursive with -d' \
  89    'git ls-tree -r -d $tree >current &&
  90     make_expected <<\EOF &&
  91040000 tree X   path2
  92040000 tree X   path2/baz
  93EOF
  94     test_output'
  95
  96test_expect_success \
  97    'ls-tree filtered with path' \
  98    'git ls-tree $tree path >current &&
  99     make_expected <<\EOF &&
 100EOF
 101     test_output'
 102
 103
 104# it used to be path1 and then path0, but with pathspec semantics
 105# they are shown in canonical order.
 106test_expect_success \
 107    'ls-tree filtered with path1 path0' \
 108    'git ls-tree $tree path1 path0 >current &&
 109     make_expected <<\EOF &&
 110100644 blob X   path0
 111120000 blob X   path1
 112EOF
 113     test_output'
 114
 115test_expect_success \
 116    'ls-tree filtered with path0/' \
 117    'git ls-tree $tree path0/ >current &&
 118     make_expected <<\EOF &&
 119EOF
 120     test_output'
 121
 122# It used to show path2 and its immediate children but
 123# with pathspec semantics it shows only path2
 124test_expect_success \
 125    'ls-tree filtered with path2' \
 126    'git ls-tree $tree path2 >current &&
 127     make_expected <<\EOF &&
 128040000 tree X   path2
 129EOF
 130     test_output'
 131
 132# ... and path2/ shows the children.
 133test_expect_success \
 134    'ls-tree filtered with path2/' \
 135    'git ls-tree $tree path2/ >current &&
 136     make_expected <<\EOF &&
 137040000 tree X   path2/baz
 138120000 blob X   path2/bazbo
 139100644 blob X   path2/foo
 140EOF
 141     test_output'
 142
 143# The same change -- exact match does not show children of
 144# path2/baz
 145test_expect_success \
 146    'ls-tree filtered with path2/baz' \
 147    'git ls-tree $tree path2/baz >current &&
 148     make_expected <<\EOF &&
 149040000 tree X   path2/baz
 150EOF
 151     test_output'
 152
 153test_expect_success \
 154    'ls-tree filtered with path2/bak' \
 155    'git ls-tree $tree path2/bak >current &&
 156     make_expected <<\EOF &&
 157EOF
 158     test_output'
 159
 160test_expect_success \
 161    'ls-tree -t filtered with path2/bak' \
 162    'git ls-tree -t $tree path2/bak >current &&
 163     make_expected <<\EOF &&
 164040000 tree X   path2
 165EOF
 166     test_output'
 167
 168test_expect_success \
 169    'ls-tree with one path a prefix of the other' \
 170    'git ls-tree $tree path2/baz path2/bazbo >current &&
 171     make_expected <<\EOF &&
 172040000 tree X   path2/baz
 173120000 blob X   path2/bazbo
 174EOF
 175     test_output'
 176
 177test_done