Git fork
at reftables-rust 166 lines 3.9 kB view raw
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 20. ./test-lib.sh 21 22test_expect_success \ 23 'setup' \ 24 'mkdir path2 path2/baz && 25 echo Hi >path0 && 26 test_ln_s_add path0 path1 && 27 test_ln_s_add ../path1 path2/bazbo && 28 echo Lo >path2/foo && 29 echo Mi >path2/baz/b && 30 find path? \( -type f -o -type l \) -print | 31 xargs git update-index --add && 32 tree=$(git write-tree) && 33 echo $tree' 34 35test_output () { 36 sed -e "s/ $OID_REGEX / X /" <current >check 37 test_cmp expected check 38} 39 40test_expect_success \ 41 'ls-tree plain' \ 42 'git ls-tree $tree >current && 43 cat >expected <<\EOF && 44100644 blob X path0 45120000 blob X path1 46040000 tree X path2 47EOF 48 test_output' 49 50test_expect_success \ 51 'ls-tree recursive' \ 52 'git ls-tree -r $tree >current && 53 cat >expected <<\EOF && 54100644 blob X path0 55120000 blob X path1 56100644 blob X path2/baz/b 57120000 blob X path2/bazbo 58100644 blob X path2/foo 59EOF 60 test_output' 61 62test_expect_success \ 63 'ls-tree recursive with -t' \ 64 'git ls-tree -r -t $tree >current && 65 cat >expected <<\EOF && 66100644 blob X path0 67120000 blob X path1 68040000 tree X path2 69040000 tree X path2/baz 70100644 blob X path2/baz/b 71120000 blob X path2/bazbo 72100644 blob X path2/foo 73EOF 74 test_output' 75 76test_expect_success \ 77 'ls-tree recursive with -d' \ 78 'git ls-tree -r -d $tree >current && 79 cat >expected <<\EOF && 80040000 tree X path2 81040000 tree X path2/baz 82EOF 83 test_output' 84 85test_expect_success \ 86 'ls-tree filtered with path' \ 87 'git ls-tree $tree path >current && 88 cat >expected <<\EOF && 89EOF 90 test_output' 91 92 93# it used to be path1 and then path0, but with pathspec semantics 94# they are shown in canonical order. 95test_expect_success \ 96 'ls-tree filtered with path1 path0' \ 97 'git ls-tree $tree path1 path0 >current && 98 cat >expected <<\EOF && 99100644 blob X path0 100120000 blob X path1 101EOF 102 test_output' 103 104test_expect_success \ 105 'ls-tree filtered with path0/' \ 106 'git ls-tree $tree path0/ >current && 107 cat >expected <<\EOF && 108EOF 109 test_output' 110 111# It used to show path2 and its immediate children but 112# with pathspec semantics it shows only path2 113test_expect_success \ 114 'ls-tree filtered with path2' \ 115 'git ls-tree $tree path2 >current && 116 cat >expected <<\EOF && 117040000 tree X path2 118EOF 119 test_output' 120 121# ... and path2/ shows the children. 122test_expect_success \ 123 'ls-tree filtered with path2/' \ 124 'git ls-tree $tree path2/ >current && 125 cat >expected <<\EOF && 126040000 tree X path2/baz 127120000 blob X path2/bazbo 128100644 blob X path2/foo 129EOF 130 test_output' 131 132# The same change -- exact match does not show children of 133# path2/baz 134test_expect_success \ 135 'ls-tree filtered with path2/baz' \ 136 'git ls-tree $tree path2/baz >current && 137 cat >expected <<\EOF && 138040000 tree X path2/baz 139EOF 140 test_output' 141 142test_expect_success \ 143 'ls-tree filtered with path2/bak' \ 144 'git ls-tree $tree path2/bak >current && 145 cat >expected <<\EOF && 146EOF 147 test_output' 148 149test_expect_success \ 150 'ls-tree -t filtered with path2/bak' \ 151 'git ls-tree -t $tree path2/bak >current && 152 cat >expected <<\EOF && 153040000 tree X path2 154EOF 155 test_output' 156 157test_expect_success \ 158 'ls-tree with one path a prefix of the other' \ 159 'git ls-tree $tree path2/baz path2/bazbo >current && 160 cat >expected <<\EOF && 161040000 tree X path2/baz 162120000 blob X path2/bazbo 163EOF 164 test_output' 165 166test_done