]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3100-ls-tree-restrict.sh
sha1_file.c: move find_cached_object up so sha1_object_info can use it
[thirdparty/git.git] / t / t3100-ls-tree-restrict.sh
CommitLineData
6d3a5077
JM
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git ls-tree test.
6d3a5077 7
5be60078 8This test runs git ls-tree with the following in a tree.
6d3a5077
JM
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
66204988 17path2/baz. Also path0/ should snow nothing.
6d3a5077
JM
18'
19. ./test-lib.sh
20
21test_expect_success \
22 'setup' \
23 'mkdir path2 path2/baz &&
24 echo Hi >path0 &&
704a3143
JS
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 &&
6d3a5077 39 echo Lo >path2/foo &&
6d3a5077
JM
40 echo Mi >path2/baz/b &&
41 find path? \( -type f -o -type l \) -print |
5be60078
JH
42 xargs git update-index --add &&
43 tree=`git write-tree` &&
6d3a5077
JM
44 echo $tree'
45
6d3a5077 46test_output () {
2eab945e 47 sed -e "s/ $_x40 / X /" <current >check
3af82863 48 test_cmp expected check
6d3a5077
JM
49}
50
51test_expect_success \
52 'ls-tree plain' \
5be60078 53 'git ls-tree $tree >current &&
704a3143 54 make_expected <<\EOF &&
2eab945e
JH
55100644 blob X path0
56120000 blob X path1
57040000 tree X path2
6d3a5077
JM
58EOF
59 test_output'
60
61test_expect_success \
62 'ls-tree recursive' \
5be60078 63 'git ls-tree -r $tree >current &&
704a3143 64 make_expected <<\EOF &&
2eab945e
JH
65100644 blob X path0
66120000 blob X path1
2eab945e
JH
67100644 blob X path2/baz/b
68120000 blob X path2/bazbo
69100644 blob X path2/foo
6d3a5077
JM
70EOF
71 test_output'
72
57ae0d09
JH
73test_expect_success \
74 'ls-tree recursive with -t' \
5be60078 75 'git ls-tree -r -t $tree >current &&
704a3143 76 make_expected <<\EOF &&
57ae0d09
JH
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' \
5be60078 89 'git ls-tree -r -d $tree >current &&
704a3143 90 make_expected <<\EOF &&
57ae0d09
JH
91040000 tree X path2
92040000 tree X path2/baz
93EOF
94 test_output'
95
6d3a5077 96test_expect_success \
66204988 97 'ls-tree filtered with path' \
5be60078 98 'git ls-tree $tree path >current &&
704a3143 99 make_expected <<\EOF &&
6d3a5077
JM
100EOF
101 test_output'
102
103
246cc52f
JH
104# it used to be path1 and then path0, but with pathspec semantics
105# they are shown in canonical order.
6d3a5077 106test_expect_success \
66204988 107 'ls-tree filtered with path1 path0' \
5be60078 108 'git ls-tree $tree path1 path0 >current &&
704a3143 109 make_expected <<\EOF &&
6af1f019 110100644 blob X path0
246cc52f 111120000 blob X path1
6d3a5077
JM
112EOF
113 test_output'
114
115test_expect_success \
66204988 116 'ls-tree filtered with path0/' \
5be60078 117 'git ls-tree $tree path0/ >current &&
704a3143 118 make_expected <<\EOF &&
66204988
JH
119EOF
120 test_output'
121
246cc52f
JH
122# It used to show path2 and its immediate children but
123# with pathspec semantics it shows only path2
66204988
JH
124test_expect_success \
125 'ls-tree filtered with path2' \
5be60078 126 'git ls-tree $tree path2 >current &&
704a3143 127 make_expected <<\EOF &&
2eab945e 128040000 tree X path2
6d3a5077
JM
129EOF
130 test_output'
131
246cc52f 132# ... and path2/ shows the children.
66204988 133test_expect_success \
246cc52f 134 'ls-tree filtered with path2/' \
5be60078 135 'git ls-tree $tree path2/ >current &&
704a3143 136 make_expected <<\EOF &&
66204988
JH
137040000 tree X path2/baz
138120000 blob X path2/bazbo
139100644 blob X path2/foo
140EOF
141 test_output'
142
246cc52f
JH
143# The same change -- exact match does not show children of
144# path2/baz
66204988 145test_expect_success \
246cc52f 146 'ls-tree filtered with path2/baz' \
5be60078 147 'git ls-tree $tree path2/baz >current &&
704a3143 148 make_expected <<\EOF &&
66204988 149040000 tree X path2/baz
66204988
JH
150EOF
151 test_output'
152
57ae0d09
JH
153test_expect_success \
154 'ls-tree filtered with path2/bak' \
5be60078 155 'git ls-tree $tree path2/bak >current &&
704a3143 156 make_expected <<\EOF &&
57ae0d09
JH
157EOF
158 test_output'
159
160test_expect_success \
161 'ls-tree -t filtered with path2/bak' \
5be60078 162 'git ls-tree -t $tree path2/bak >current &&
704a3143 163 make_expected <<\EOF &&
57ae0d09
JH
164040000 tree X path2
165EOF
166 test_output'
167
b294ed63
JH
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
6d3a5077 177test_done