t / t3101-ls-tree-dirname.shon commit builtin-rev-list.c: mark file-local function static (f1c92c6)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4# Copyright (c) 2005 Robert Fitzsimons
   5#
   6
   7test_description='git ls-tree directory and filenames handling.
   8
   9This test runs git ls-tree with the following in a tree.
  10
  11    1.txt              - a file
  12    2.txt              - a file
  13    path0/a/b/c/1.txt  - a file in a directory
  14    path1/b/c/1.txt    - a file in a directory
  15    path2/1.txt        - a file in a directory
  16    path3/1.txt        - a file in a directory
  17    path3/2.txt        - a file in a directory
  18
  19Test the handling of mulitple directories which have matching file
  20entries.  Also test odd filename and missing entries handling.
  21'
  22. ./test-lib.sh
  23
  24test_expect_success \
  25    'setup' \
  26    'echo 111 >1.txt &&
  27     echo 222 >2.txt &&
  28     mkdir path0 path0/a path0/a/b path0/a/b/c &&
  29     echo 111 >path0/a/b/c/1.txt &&
  30     mkdir path1 path1/b path1/b/c &&
  31     echo 111 >path1/b/c/1.txt &&
  32     mkdir path2 &&
  33     echo 111 >path2/1.txt &&
  34     mkdir path3 &&
  35     echo 111 >path3/1.txt &&
  36     echo 222 >path3/2.txt &&
  37     find *.txt path* \( -type f -o -type l \) -print |
  38     xargs git update-index --add &&
  39     tree=`git write-tree` &&
  40     echo $tree'
  41
  42_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  43_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
  44test_output () {
  45    sed -e "s/ $_x40    / X     /" <current >check
  46    test_cmp expected check
  47}
  48
  49test_expect_success \
  50    'ls-tree plain' \
  51    'git ls-tree $tree >current &&
  52     cat >expected <<\EOF &&
  53100644 blob X   1.txt
  54100644 blob X   2.txt
  55040000 tree X   path0
  56040000 tree X   path1
  57040000 tree X   path2
  58040000 tree X   path3
  59EOF
  60     test_output'
  61
  62# Recursive does not show tree nodes anymore...
  63test_expect_success \
  64    'ls-tree recursive' \
  65    'git ls-tree -r $tree >current &&
  66     cat >expected <<\EOF &&
  67100644 blob X   1.txt
  68100644 blob X   2.txt
  69100644 blob X   path0/a/b/c/1.txt
  70100644 blob X   path1/b/c/1.txt
  71100644 blob X   path2/1.txt
  72100644 blob X   path3/1.txt
  73100644 blob X   path3/2.txt
  74EOF
  75     test_output'
  76
  77test_expect_success \
  78    'ls-tree filter 1.txt' \
  79    'git ls-tree $tree 1.txt >current &&
  80     cat >expected <<\EOF &&
  81100644 blob X   1.txt
  82EOF
  83     test_output'
  84
  85test_expect_success \
  86    'ls-tree filter path1/b/c/1.txt' \
  87    'git ls-tree $tree path1/b/c/1.txt >current &&
  88     cat >expected <<\EOF &&
  89100644 blob X   path1/b/c/1.txt
  90EOF
  91     test_output'
  92
  93test_expect_success \
  94    'ls-tree filter all 1.txt files' \
  95    'git ls-tree $tree 1.txt path0/a/b/c/1.txt path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
  96     cat >expected <<\EOF &&
  97100644 blob X   1.txt
  98100644 blob X   path0/a/b/c/1.txt
  99100644 blob X   path1/b/c/1.txt
 100100644 blob X   path2/1.txt
 101100644 blob X   path3/1.txt
 102EOF
 103     test_output'
 104
 105# I am not so sure about this one after ls-tree doing pathspec match.
 106# Having both path0/a and path0/a/b/c makes path0/a redundant, and
 107# it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified.
 108test_expect_success \
 109    'ls-tree filter directories' \
 110    'git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
 111     cat >expected <<\EOF &&
 112040000 tree X   path0/a/b/c
 113040000 tree X   path1/b/c
 114040000 tree X   path2
 115040000 tree X   path3
 116EOF
 117     test_output'
 118
 119# Again, duplicates are filtered away so this is equivalent to
 120# having 1.txt and path3
 121test_expect_success \
 122    'ls-tree filter odd names' \
 123    'git ls-tree $tree 1.txt ./1.txt .//1.txt path3/1.txt path3/./1.txt path3 path3// >current &&
 124     cat >expected <<\EOF &&
 125100644 blob X   1.txt
 126100644 blob X   path3/1.txt
 127100644 blob X   path3/2.txt
 128EOF
 129     test_output'
 130
 131test_expect_success \
 132    'ls-tree filter missing files and extra slashes' \
 133    'git ls-tree $tree 1.txt/ abc.txt path3//23.txt path3/2.txt/// >current &&
 134     cat >expected <<\EOF &&
 135EOF
 136     test_output'
 137
 138test_expect_success 'ls-tree filter is leading path match' '
 139        git ls-tree $tree pa path3/a >current &&
 140        >expected &&
 141        test_output
 142'
 143
 144test_expect_success 'ls-tree --full-name' '
 145        (
 146                cd path0 &&
 147                git ls-tree --full-name $tree a
 148        ) >current &&
 149        cat >expected <<\EOF &&
 150040000 tree X   path0/a
 151EOF
 152        test_output
 153'
 154
 155test_expect_success 'ls-tree --full-tree' '
 156        (
 157                cd path1/b/c &&
 158                git ls-tree --full-tree $tree
 159        ) >current &&
 160        cat >expected <<\EOF &&
 161100644 blob X   1.txt
 162100644 blob X   2.txt
 163040000 tree X   path0
 164040000 tree X   path1
 165040000 tree X   path2
 166040000 tree X   path3
 167EOF
 168        test_output
 169'
 170
 171test_expect_success 'ls-tree --full-tree -r' '
 172        (
 173                cd path3/ &&
 174                git ls-tree --full-tree -r $tree
 175        ) >current &&
 176        cat >expected <<\EOF &&
 177100644 blob X   1.txt
 178100644 blob X   2.txt
 179100644 blob X   path0/a/b/c/1.txt
 180100644 blob X   path1/b/c/1.txt
 181100644 blob X   path2/1.txt
 182100644 blob X   path3/1.txt
 183100644 blob X   path3/2.txt
 184EOF
 185        test_output
 186'
 187
 188test_expect_success 'ls-tree --abbrev=5' '
 189        git ls-tree --abbrev=5 $tree >current &&
 190        sed -e "s/ $_x05[0-9a-f]*       / X     /" <current >check &&
 191        cat >expected <<\EOF &&
 192100644 blob X   1.txt
 193100644 blob X   2.txt
 194040000 tree X   path0
 195040000 tree X   path1
 196040000 tree X   path2
 197040000 tree X   path3
 198EOF
 199        test_cmp expected check
 200'
 201
 202test_expect_success 'ls-tree --name-only' '
 203        git ls-tree --name-only $tree >current
 204        cat >expected <<\EOF &&
 2051.txt
 2062.txt
 207path0
 208path1
 209path2
 210path3
 211EOF
 212        test_output
 213'
 214
 215test_expect_success 'ls-tree --name-only -r' '
 216        git ls-tree --name-only -r $tree >current
 217        cat >expected <<\EOF &&
 2181.txt
 2192.txt
 220path0/a/b/c/1.txt
 221path1/b/c/1.txt
 222path2/1.txt
 223path3/1.txt
 224path3/2.txt
 225EOF
 226        test_output
 227'
 228
 229test_done