]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3100-ls-tree-restrict.sh
path.c: don't call the match function without value in trie_find()
[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 &&
e40db07f
JS
25 test_ln_s_add path0 path1 &&
26 test_ln_s_add ../path1 path2/bazbo &&
6d3a5077 27 echo Lo >path2/foo &&
6d3a5077
JM
28 echo Mi >path2/baz/b &&
29 find path? \( -type f -o -type l \) -print |
5be60078 30 xargs git update-index --add &&
10c1e855 31 tree=$(git write-tree) &&
6d3a5077
JM
32 echo $tree'
33
6d3a5077 34test_output () {
2ece6ad2 35 sed -e "s/ $OID_REGEX / X /" <current >check
3af82863 36 test_cmp expected check
6d3a5077
JM
37}
38
39test_expect_success \
40 'ls-tree plain' \
5be60078 41 'git ls-tree $tree >current &&
e40db07f 42 cat >expected <<\EOF &&
2eab945e
JH
43100644 blob X path0
44120000 blob X path1
45040000 tree X path2
6d3a5077
JM
46EOF
47 test_output'
48
49test_expect_success \
50 'ls-tree recursive' \
5be60078 51 'git ls-tree -r $tree >current &&
e40db07f 52 cat >expected <<\EOF &&
2eab945e
JH
53100644 blob X path0
54120000 blob X path1
2eab945e
JH
55100644 blob X path2/baz/b
56120000 blob X path2/bazbo
57100644 blob X path2/foo
6d3a5077
JM
58EOF
59 test_output'
60
57ae0d09
JH
61test_expect_success \
62 'ls-tree recursive with -t' \
5be60078 63 'git ls-tree -r -t $tree >current &&
e40db07f 64 cat >expected <<\EOF &&
57ae0d09
JH
65100644 blob X path0
66120000 blob X path1
67040000 tree X path2
68040000 tree X path2/baz
69100644 blob X path2/baz/b
70120000 blob X path2/bazbo
71100644 blob X path2/foo
72EOF
73 test_output'
74
75test_expect_success \
76 'ls-tree recursive with -d' \
5be60078 77 'git ls-tree -r -d $tree >current &&
e40db07f 78 cat >expected <<\EOF &&
57ae0d09
JH
79040000 tree X path2
80040000 tree X path2/baz
81EOF
82 test_output'
83
6d3a5077 84test_expect_success \
66204988 85 'ls-tree filtered with path' \
5be60078 86 'git ls-tree $tree path >current &&
e40db07f 87 cat >expected <<\EOF &&
6d3a5077
JM
88EOF
89 test_output'
90
91
246cc52f
JH
92# it used to be path1 and then path0, but with pathspec semantics
93# they are shown in canonical order.
6d3a5077 94test_expect_success \
66204988 95 'ls-tree filtered with path1 path0' \
5be60078 96 'git ls-tree $tree path1 path0 >current &&
e40db07f 97 cat >expected <<\EOF &&
6af1f019 98100644 blob X path0
246cc52f 99120000 blob X path1
6d3a5077
JM
100EOF
101 test_output'
102
103test_expect_success \
66204988 104 'ls-tree filtered with path0/' \
5be60078 105 'git ls-tree $tree path0/ >current &&
e40db07f 106 cat >expected <<\EOF &&
66204988
JH
107EOF
108 test_output'
109
246cc52f
JH
110# It used to show path2 and its immediate children but
111# with pathspec semantics it shows only path2
66204988
JH
112test_expect_success \
113 'ls-tree filtered with path2' \
5be60078 114 'git ls-tree $tree path2 >current &&
e40db07f 115 cat >expected <<\EOF &&
2eab945e 116040000 tree X path2
6d3a5077
JM
117EOF
118 test_output'
119
246cc52f 120# ... and path2/ shows the children.
66204988 121test_expect_success \
246cc52f 122 'ls-tree filtered with path2/' \
5be60078 123 'git ls-tree $tree path2/ >current &&
e40db07f 124 cat >expected <<\EOF &&
66204988
JH
125040000 tree X path2/baz
126120000 blob X path2/bazbo
127100644 blob X path2/foo
128EOF
129 test_output'
130
246cc52f
JH
131# The same change -- exact match does not show children of
132# path2/baz
66204988 133test_expect_success \
246cc52f 134 'ls-tree filtered with path2/baz' \
5be60078 135 'git ls-tree $tree path2/baz >current &&
e40db07f 136 cat >expected <<\EOF &&
66204988 137040000 tree X path2/baz
66204988
JH
138EOF
139 test_output'
140
57ae0d09
JH
141test_expect_success \
142 'ls-tree filtered with path2/bak' \
5be60078 143 'git ls-tree $tree path2/bak >current &&
e40db07f 144 cat >expected <<\EOF &&
57ae0d09
JH
145EOF
146 test_output'
147
148test_expect_success \
149 'ls-tree -t filtered with path2/bak' \
5be60078 150 'git ls-tree -t $tree path2/bak >current &&
e40db07f 151 cat >expected <<\EOF &&
57ae0d09
JH
152040000 tree X path2
153EOF
154 test_output'
155
b294ed63
JH
156test_expect_success \
157 'ls-tree with one path a prefix of the other' \
158 'git ls-tree $tree path2/baz path2/bazbo >current &&
e40db07f 159 cat >expected <<\EOF &&
b294ed63
JH
160040000 tree X path2/baz
161120000 blob X path2/bazbo
162EOF
163 test_output'
164
6d3a5077 165test_done