t / t3101-ls-tree-dirname.shon commit git-daemon: timeout, eliminate double DWIM (b7080d8)
   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_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  43_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
  44test_output () {
  45    sed -e "s/ $_x40    / X     /" <current >check
  46    diff -u 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
  62test_expect_success \
  63    'ls-tree recursive' \
  64    'git-ls-tree -r $tree >current &&
  65     cat >expected <<\EOF &&
  66100644 blob X   1.txt
  67100644 blob X   2.txt
  68040000 tree X   path0
  69040000 tree X   path0/a
  70040000 tree X   path0/a/b
  71040000 tree X   path0/a/b/c
  72100644 blob X   path0/a/b/c/1.txt
  73040000 tree X   path1
  74040000 tree X   path1/b
  75040000 tree X   path1/b/c
  76100644 blob X   path1/b/c/1.txt
  77040000 tree X   path2
  78100644 blob X   path2/1.txt
  79040000 tree X   path3
  80100644 blob X   path3/1.txt
  81100644 blob X   path3/2.txt
  82EOF
  83     test_output'
  84
  85test_expect_success \
  86    'ls-tree filter 1.txt' \
  87    'git-ls-tree $tree 1.txt >current &&
  88     cat >expected <<\EOF &&
  89100644 blob X   1.txt
  90EOF
  91     test_output'
  92
  93test_expect_success \
  94    'ls-tree filter path1/b/c/1.txt' \
  95    'git-ls-tree $tree path1/b/c/1.txt >current &&
  96     cat >expected <<\EOF &&
  97100644 blob X   path1/b/c/1.txt
  98EOF
  99     test_output'
 100
 101test_expect_success \
 102    'ls-tree filter all 1.txt files' \
 103    'git-ls-tree $tree 1.txt path0/a/b/c/1.txt path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
 104     cat >expected <<\EOF &&
 105100644 blob X   1.txt
 106100644 blob X   path0/a/b/c/1.txt
 107100644 blob X   path1/b/c/1.txt
 108100644 blob X   path2/1.txt
 109100644 blob X   path3/1.txt
 110EOF
 111     test_output'
 112
 113test_expect_success \
 114    'ls-tree filter directories' \
 115    'git-ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
 116     cat >expected <<\EOF &&
 117040000 tree X   path3
 118100644 blob X   path3/1.txt
 119100644 blob X   path3/2.txt
 120040000 tree X   path2
 121100644 blob X   path2/1.txt
 122040000 tree X   path0/a/b/c
 123100644 blob X   path0/a/b/c/1.txt
 124040000 tree X   path1/b/c
 125100644 blob X   path1/b/c/1.txt
 126040000 tree X   path0/a
 127040000 tree X   path0/a/b
 128EOF
 129     test_output'
 130
 131test_expect_success \
 132    'ls-tree filter odd names' \
 133    'git-ls-tree $tree 1.txt /1.txt //1.txt path3/1.txt /path3/1.txt //path3//1.txt path3 /path3/ path3// >current &&
 134     cat >expected <<\EOF &&
 135100644 blob X   1.txt
 136100644 blob X   1.txt
 137100644 blob X   1.txt
 138100644 blob X   path3/1.txt
 139100644 blob X   path3/1.txt
 140100644 blob X   path3/1.txt
 141040000 tree X   path3
 142100644 blob X   path3/1.txt
 143100644 blob X   path3/2.txt
 144040000 tree X   path3
 145100644 blob X   path3/1.txt
 146100644 blob X   path3/2.txt
 147040000 tree X   path3
 148100644 blob X   path3/1.txt
 149100644 blob X   path3/2.txt
 150EOF
 151     test_output'
 152
 153test_expect_success \
 154    'ls-tree filter missing files and extra slashes' \
 155    'git-ls-tree $tree 1.txt/ abc.txt path3//23.txt path3/2.txt/// >current &&
 156     cat >expected <<\EOF &&
 157EOF
 158     test_output'
 159
 160test_done