#!/bin/sh # # Copyright (c) 2005 Junio C Hamano # Copyright (c) 2005 Robert Fitzsimons # global test_description := ''git ls-tree directory and filenames handling. This test runs git ls-tree with the following in a tree. 1.txt - a file 2.txt - a file path0/a/b/c/1.txt - a file in a directory path1/b/c/1.txt - a file in a directory path2/1.txt - a file in a directory path3/1.txt - a file in a directory path3/2.txt - a file in a directory Test the handling of multiple directories which have matching file entries. Also test odd filename and missing entries handling. '' source ./test-lib.sh test_expect_success 'setup' ' echo 111 >1.txt && echo 222 >2.txt && mkdir path0 path0/a path0/a/b path0/a/b/c && echo 111 >path0/a/b/c/1.txt && mkdir path1 path1/b path1/b/c && echo 111 >path1/b/c/1.txt && mkdir path2 && echo 111 >path2/1.txt && mkdir path3 && echo 111 >path3/1.txt && echo 222 >path3/2.txt && find *.txt path* \( -type f -o -type l \) -print | xargs git update-index --add && tree=$(git write-tree) && echo $tree ' proc test_output { sed -e "s/ $_x40 / X /" check && test_cmp expected check } test_expect_success 'ls-tree plain' ' git ls-tree $tree >current && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X 2.txt 040000 tree X path0 040000 tree X path1 040000 tree X path2 040000 tree X path3 EOF test_output ' # Recursive does not show tree nodes anymore... test_expect_success 'ls-tree recursive' ' git ls-tree -r $tree >current && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X 2.txt 100644 blob X path0/a/b/c/1.txt 100644 blob X path1/b/c/1.txt 100644 blob X path2/1.txt 100644 blob X path3/1.txt 100644 blob X path3/2.txt EOF test_output ' test_expect_success 'ls-tree filter 1.txt' ' git ls-tree $tree 1.txt >current && cat >expected <<\EOF && 100644 blob X 1.txt EOF test_output ' test_expect_success 'ls-tree filter path1/b/c/1.txt' ' git ls-tree $tree path1/b/c/1.txt >current && cat >expected <<\EOF && 100644 blob X path1/b/c/1.txt EOF test_output ' test_expect_success 'ls-tree filter all 1.txt files' ' git ls-tree $tree 1.txt path0/a/b/c/1.txt \ path1/b/c/1.txt path2/1.txt path3/1.txt >current && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X path0/a/b/c/1.txt 100644 blob X path1/b/c/1.txt 100644 blob X path2/1.txt 100644 blob X path3/1.txt EOF test_output ' # I am not so sure about this one after ls-tree doing pathspec match. # Having both path0/a and path0/a/b/c makes path0/a redundant, and # it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified. test_expect_success 'ls-tree filter directories' ' git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current && cat >expected <<\EOF && 040000 tree X path0/a/b/c 040000 tree X path1/b/c 040000 tree X path2 040000 tree X path3 EOF test_output ' # Again, duplicates are filtered away so this is equivalent to # having 1.txt and path3 test_expect_success 'ls-tree filter odd names' ' git ls-tree $tree 1.txt ./1.txt .//1.txt \ path3/1.txt path3/./1.txt path3 path3// >current && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X path3/1.txt 100644 blob X path3/2.txt EOF test_output ' test_expect_success 'ls-tree filter missing files and extra slashes' ' git ls-tree $tree 1.txt/ abc.txt \ path3//23.txt path3/2.txt/// >current && >expected && test_output ' test_expect_success 'ls-tree filter is leading path match' ' git ls-tree $tree pa path3/a >current && >expected && test_output ' test_expect_success 'ls-tree --full-name' ' ( cd path0 && git ls-tree --full-name $tree a ) >current && cat >expected <<\EOF && 040000 tree X path0/a EOF test_output ' test_expect_success 'ls-tree --full-tree' ' ( cd path1/b/c && git ls-tree --full-tree $tree ) >current && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X 2.txt 040000 tree X path0 040000 tree X path1 040000 tree X path2 040000 tree X path3 EOF test_output ' test_expect_success 'ls-tree --full-tree -r' ' ( cd path3/ && git ls-tree --full-tree -r $tree ) >current && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X 2.txt 100644 blob X path0/a/b/c/1.txt 100644 blob X path1/b/c/1.txt 100644 blob X path2/1.txt 100644 blob X path3/1.txt 100644 blob X path3/2.txt EOF test_output ' test_expect_success 'ls-tree --abbrev=5' ' git ls-tree --abbrev=5 $tree >current && sed -e "s/ $_x05[0-9a-f]* / X /" check && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X 2.txt 040000 tree X path0 040000 tree X path1 040000 tree X path2 040000 tree X path3 EOF test_cmp expected check ' test_expect_success 'ls-tree --name-only' ' git ls-tree --name-only $tree >current && cat >expected <<\EOF && 1.txt 2.txt path0 path1 path2 path3 EOF test_output ' test_expect_success 'ls-tree --name-only -r' ' git ls-tree --name-only -r $tree >current && cat >expected <<\EOF && 1.txt 2.txt path0/a/b/c/1.txt path1/b/c/1.txt path2/1.txt path3/1.txt path3/2.txt EOF test_output ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"git ls-tree directory and filenames handling.\n"> <"\n"> <"This test runs git ls-tree with the following in a tree.\n"> <"\n"> <" 1.txt - a file\n"> <" 2.txt - a file\n"> <" path0/a/b/c/1.txt - a file in a directory\n"> <" path1/b/c/1.txt - a file in a directory\n"> <" path2/1.txt - a file in a directory\n"> <" path3/1.txt - a file in a directory\n"> <" path3/2.txt - a file in a directory\n"> <"\n"> <"Test the handling of multiple directories which have matching file\n"> <"entries. Also test odd filename and missing entries handling.\n"> ) } spids: [16] ) ] spids: [16] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\techo 111 >1.txt &&\n"> <"\techo 222 >2.txt &&\n"> <"\tmkdir path0 path0/a path0/a/b path0/a/b/c &&\n"> <"\techo 111 >path0/a/b/c/1.txt &&\n"> <"\tmkdir path1 path1/b path1/b/c &&\n"> <"\techo 111 >path1/b/c/1.txt &&\n"> <"\tmkdir path2 &&\n"> <"\techo 111 >path2/1.txt &&\n"> <"\tmkdir path3 &&\n"> <"\techo 111 >path3/1.txt &&\n"> <"\techo 222 >path3/2.txt &&\n"> <"\tfind *.txt path* \\( -type f -o -type l \\) -print |\n"> <"\txargs git update-index --add &&\n"> <"\ttree=$(git write-tree) &&\n"> <"\techo $tree\n"> ) } ) (FuncDef name: test_output body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(sed)} {(-e)} {(DQ ("s/ ") ($ VSub_Name "$_x40") ("\t/ X\t/"))}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(current)} spids: [83] ) (Redir op_id:Redir_Great fd:-1 arg_word:{(check)} spids:[86]) ] ) (C {(test_cmp)} {(expected)} {(check)}) ] op_id: Op_DAmp ) ] spids: [70] ) spids: [65 69] ) (C {(test_expect_success)} {(SQ <"ls-tree plain">)} { (SQ <"\n"> <"\tgit ls-tree $tree >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"100644 blob X\t2.txt\n"> <"040000 tree X\tpath0\n"> <"040000 tree X\tpath1\n"> <"040000 tree X\tpath2\n"> <"040000 tree X\tpath3\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree recursive">)} { (SQ <"\n"> <"\tgit ls-tree -r $tree >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"100644 blob X\t2.txt\n"> <"100644 blob X\tpath0/a/b/c/1.txt\n"> <"100644 blob X\tpath1/b/c/1.txt\n"> <"100644 blob X\tpath2/1.txt\n"> <"100644 blob X\tpath3/1.txt\n"> <"100644 blob X\tpath3/2.txt\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree filter 1.txt">)} { (SQ <"\n"> <"\tgit ls-tree $tree 1.txt >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree filter path1/b/c/1.txt">)} { (SQ <"\n"> <"\tgit ls-tree $tree path1/b/c/1.txt >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\tpath1/b/c/1.txt\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree filter all 1.txt files">)} { (SQ <"\n"> <"\tgit ls-tree $tree 1.txt path0/a/b/c/1.txt \\\n"> <"\t\tpath1/b/c/1.txt path2/1.txt path3/1.txt >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"100644 blob X\tpath0/a/b/c/1.txt\n"> <"100644 blob X\tpath1/b/c/1.txt\n"> <"100644 blob X\tpath2/1.txt\n"> <"100644 blob X\tpath3/1.txt\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree filter directories">)} { (SQ <"\n"> <"\tgit ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"040000 tree X\tpath0/a/b/c\n"> <"040000 tree X\tpath1/b/c\n"> <"040000 tree X\tpath2\n"> <"040000 tree X\tpath3\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree filter odd names">)} { (SQ <"\n"> <"\tgit ls-tree $tree 1.txt ./1.txt .//1.txt \\\n"> <"\t\tpath3/1.txt path3/./1.txt path3 path3// >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"100644 blob X\tpath3/1.txt\n"> <"100644 blob X\tpath3/2.txt\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree filter missing files and extra slashes">)} { (SQ <"\n"> <"\tgit ls-tree $tree 1.txt/ abc.txt \\\n"> <"\t\tpath3//23.txt path3/2.txt/// >current &&\n"> <"\t>expected &&\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree filter is leading path match">)} { (SQ <"\n"> <"\tgit ls-tree $tree pa path3/a >current &&\n"> <"\t>expected &&\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree --full-name">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd path0 &&\n"> <"\t\tgit ls-tree --full-name $tree a\n"> <"\t) >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"040000 tree X\tpath0/a\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree --full-tree">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd path1/b/c &&\n"> <"\t\tgit ls-tree --full-tree $tree\n"> <"\t) >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"100644 blob X\t2.txt\n"> <"040000 tree X\tpath0\n"> <"040000 tree X\tpath1\n"> <"040000 tree X\tpath2\n"> <"040000 tree X\tpath3\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree --full-tree -r">)} { (SQ <"\n"> <"\t(\n"> <"\t\tcd path3/ &&\n"> <"\t\tgit ls-tree --full-tree -r $tree\n"> <"\t) >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"100644 blob X\t2.txt\n"> <"100644 blob X\tpath0/a/b/c/1.txt\n"> <"100644 blob X\tpath1/b/c/1.txt\n"> <"100644 blob X\tpath2/1.txt\n"> <"100644 blob X\tpath3/1.txt\n"> <"100644 blob X\tpath3/2.txt\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree --abbrev=5">)} { (SQ <"\n"> <"\tgit ls-tree --abbrev=5 $tree >current &&\n"> <"\tsed -e \"s/ $_x05[0-9a-f]*\t/ X\t/\" check &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"100644 blob X\t1.txt\n"> <"100644 blob X\t2.txt\n"> <"040000 tree X\tpath0\n"> <"040000 tree X\tpath1\n"> <"040000 tree X\tpath2\n"> <"040000 tree X\tpath3\n"> <"EOF\n"> <"\ttest_cmp expected check\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree --name-only">)} { (SQ <"\n"> <"\tgit ls-tree --name-only $tree >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"1.txt\n"> <"2.txt\n"> <"path0\n"> <"path1\n"> <"path2\n"> <"path3\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_expect_success)} {(SQ <"ls-tree --name-only -r">)} { (SQ <"\n"> <"\tgit ls-tree --name-only -r $tree >current &&\n"> <"\tcat >expected <<\\EOF &&\n"> <"1.txt\n"> <"2.txt\n"> <"path0/a/b/c/1.txt\n"> <"path1/b/c/1.txt\n"> <"path2/1.txt\n"> <"path3/1.txt\n"> <"path3/2.txt\n"> <"EOF\n"> <"\ttest_output\n"> ) } ) (C {(test_done)}) ] )