]>
Commit | Line | Data |
---|---|---|
6d3a5077 JM |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='git-ls-tree test. | |
7 | ||
8 | This 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 | ||
16 | The new path restriction code should do the right thing for path2 and | |
66204988 | 17 | path2/baz. Also path0/ should snow nothing. |
6d3a5077 JM |
18 | ' |
19 | . ./test-lib.sh | |
20 | ||
21 | test_expect_success \ | |
22 | 'setup' \ | |
23 | 'mkdir path2 path2/baz && | |
24 | echo Hi >path0 && | |
25 | ln -s path0 path1 && | |
26 | echo Lo >path2/foo && | |
27 | ln -s ../path1 path2/bazbo && | |
28 | echo Mi >path2/baz/b && | |
29 | find path? \( -type f -o -type l \) -print | | |
215a7ad1 | 30 | xargs git-update-index --add && |
6d3a5077 JM |
31 | tree=`git-write-tree` && |
32 | echo $tree' | |
33 | ||
34 | _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' | |
35 | _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" | |
36 | test_output () { | |
2eab945e | 37 | sed -e "s/ $_x40 / X /" <current >check |
6d3a5077 JM |
38 | diff -u expected check |
39 | } | |
40 | ||
41 | test_expect_success \ | |
42 | 'ls-tree plain' \ | |
43 | 'git-ls-tree $tree >current && | |
44 | cat >expected <<\EOF && | |
2eab945e JH |
45 | 100644 blob X path0 |
46 | 120000 blob X path1 | |
47 | 040000 tree X path2 | |
6d3a5077 JM |
48 | EOF |
49 | test_output' | |
50 | ||
51 | test_expect_success \ | |
52 | 'ls-tree recursive' \ | |
53 | 'git-ls-tree -r $tree >current && | |
54 | cat >expected <<\EOF && | |
2eab945e JH |
55 | 100644 blob X path0 |
56 | 120000 blob X path1 | |
2eab945e JH |
57 | 100644 blob X path2/baz/b |
58 | 120000 blob X path2/bazbo | |
59 | 100644 blob X path2/foo | |
6d3a5077 JM |
60 | EOF |
61 | test_output' | |
62 | ||
63 | test_expect_success \ | |
66204988 | 64 | 'ls-tree filtered with path' \ |
6d3a5077 JM |
65 | 'git-ls-tree $tree path >current && |
66 | cat >expected <<\EOF && | |
67 | EOF | |
68 | test_output' | |
69 | ||
70 | ||
246cc52f JH |
71 | # it used to be path1 and then path0, but with pathspec semantics |
72 | # they are shown in canonical order. | |
6d3a5077 | 73 | test_expect_success \ |
66204988 | 74 | 'ls-tree filtered with path1 path0' \ |
6d3a5077 JM |
75 | 'git-ls-tree $tree path1 path0 >current && |
76 | cat >expected <<\EOF && | |
6af1f019 | 77 | 100644 blob X path0 |
246cc52f | 78 | 120000 blob X path1 |
6d3a5077 JM |
79 | EOF |
80 | test_output' | |
81 | ||
82 | test_expect_success \ | |
66204988 JH |
83 | 'ls-tree filtered with path0/' \ |
84 | 'git-ls-tree $tree path0/ >current && | |
85 | cat >expected <<\EOF && | |
86 | EOF | |
87 | test_output' | |
88 | ||
246cc52f JH |
89 | # It used to show path2 and its immediate children but |
90 | # with pathspec semantics it shows only path2 | |
66204988 JH |
91 | test_expect_success \ |
92 | 'ls-tree filtered with path2' \ | |
6d3a5077 JM |
93 | 'git-ls-tree $tree path2 >current && |
94 | cat >expected <<\EOF && | |
2eab945e | 95 | 040000 tree X path2 |
6d3a5077 JM |
96 | EOF |
97 | test_output' | |
98 | ||
246cc52f | 99 | # ... and path2/ shows the children. |
66204988 | 100 | test_expect_success \ |
246cc52f JH |
101 | 'ls-tree filtered with path2/' \ |
102 | 'git-ls-tree $tree path2/ >current && | |
66204988 | 103 | cat >expected <<\EOF && |
66204988 JH |
104 | 040000 tree X path2/baz |
105 | 120000 blob X path2/bazbo | |
106 | 100644 blob X path2/foo | |
107 | EOF | |
108 | test_output' | |
109 | ||
246cc52f JH |
110 | # The same change -- exact match does not show children of |
111 | # path2/baz | |
66204988 | 112 | test_expect_success \ |
246cc52f JH |
113 | 'ls-tree filtered with path2/baz' \ |
114 | 'git-ls-tree $tree path2/baz >current && | |
66204988 | 115 | cat >expected <<\EOF && |
66204988 | 116 | 040000 tree X path2/baz |
66204988 JH |
117 | EOF |
118 | test_output' | |
119 | ||
6d3a5077 | 120 | test_done |