Merge branch 'es/maintenance-of-bare-repositories'
[git/debian.git] / t / t4010-diff-pathspec.sh
blob1bbced79ece861e2329663b09e8aead3daa983e0
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Pathspec restrictions
8 Prepare:
9 file0
10 path1/file1
12 . ./test-lib.sh
13 . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
15 test_expect_success \
16 setup \
17 'echo frotz >file0 &&
18 mkdir path1 &&
19 echo rezrov >path1/file1 &&
20 before0=$(git hash-object file0) &&
21 before1=$(git hash-object path1/file1) &&
22 git update-index --add file0 path1/file1 &&
23 tree=$(git write-tree) &&
24 echo "$tree" &&
25 echo nitfol >file0 &&
26 echo yomin >path1/file1 &&
27 after0=$(git hash-object file0) &&
28 after1=$(git hash-object path1/file1) &&
29 git update-index file0 path1/file1'
31 cat >expected <<\EOF
32 EOF
33 test_expect_success \
34 'limit to path should show nothing' \
35 'git diff-index --cached $tree -- path >current &&
36 compare_diff_raw current expected'
38 cat >expected <<EOF
39 :100644 100644 $before1 $after1 M path1/file1
40 EOF
41 test_expect_success \
42 'limit to path1 should show path1/file1' \
43 'git diff-index --cached $tree -- path1 >current &&
44 compare_diff_raw current expected'
46 cat >expected <<EOF
47 :100644 100644 $before1 $after1 M path1/file1
48 EOF
49 test_expect_success \
50 'limit to path1/ should show path1/file1' \
51 'git diff-index --cached $tree -- path1/ >current &&
52 compare_diff_raw current expected'
54 cat >expected <<EOF
55 :100644 100644 $before1 $after1 M path1/file1
56 EOF
57 test_expect_success \
58 '"*file1" should show path1/file1' \
59 'git diff-index --cached $tree -- "*file1" >current &&
60 compare_diff_raw current expected'
62 cat >expected <<EOF
63 :100644 100644 $before0 $after0 M file0
64 EOF
65 test_expect_success \
66 'limit to file0 should show file0' \
67 'git diff-index --cached $tree -- file0 >current &&
68 compare_diff_raw current expected'
70 cat >expected <<\EOF
71 EOF
72 test_expect_success \
73 'limit to file0/ should emit nothing.' \
74 'git diff-index --cached $tree -- file0/ >current &&
75 compare_diff_raw current expected'
77 test_expect_success 'diff-tree pathspec' '
78 tree2=$(git write-tree) &&
79 echo "$tree2" &&
80 git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
81 test_must_be_empty current
84 test_expect_success 'diff-tree with wildcard shows dir also matches' '
85 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
86 echo file0 >expected &&
87 test_cmp expected result
90 test_expect_success 'diff-tree -r with wildcard' '
91 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
92 echo path1/file1 >expected &&
93 test_cmp expected result
96 test_expect_success 'diff-tree with wildcard shows dir also matches' '
97 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
98 echo path1 >expected &&
99 test_cmp expected result
102 test_expect_success 'diff-tree -r with wildcard from beginning' '
103 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
104 echo path1/file1 >expected &&
105 test_cmp expected result
108 test_expect_success 'diff-tree -r with wildcard' '
109 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
110 echo path1/file1 >expected &&
111 test_cmp expected result
114 test_expect_success 'setup submodules' '
115 test_tick &&
116 git init submod &&
117 ( cd submod && test_commit first ) &&
118 git add submod &&
119 git commit -m first &&
120 ( cd submod && test_commit second ) &&
121 git add submod &&
122 git commit -m second
125 test_expect_success 'diff-tree ignores trailing slash on submodule path' '
126 git diff --name-only HEAD^ HEAD submod >expect &&
127 git diff --name-only HEAD^ HEAD submod/ >actual &&
128 test_cmp expect actual &&
129 git diff --name-only HEAD^ HEAD -- submod/whatever >actual &&
130 test_must_be_empty actual
133 test_expect_success 'diff multiple wildcard pathspecs' '
134 mkdir path2 &&
135 echo rezrov >path2/file1 &&
136 git update-index --add path2/file1 &&
137 tree3=$(git write-tree) &&
138 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
139 cat <<-\EOF >expect &&
140 path1/file1
141 path2/file1
143 test_cmp expect actual
146 test_expect_success 'diff-cache ignores trailing slash on submodule path' '
147 git diff --name-only HEAD^ submod >expect &&
148 git diff --name-only HEAD^ submod/ >actual &&
149 test_cmp expect actual
152 test_done