vimdiff: make script and tests work with zsh
[alt-git.git] / t / t4010-diff-pathspec.sh
blob9d9650eba7e9774963b941fe8ebf82925af14ec9
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Pathspec restrictions
8 Prepare:
9 file0
10 path1/file1
13 TEST_PASSES_SANITIZE_LEAK=true
14 . ./test-lib.sh
15 . "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
17 test_expect_success \
18 setup \
19 'echo frotz >file0 &&
20 mkdir path1 &&
21 echo rezrov >path1/file1 &&
22 before0=$(git hash-object file0) &&
23 before1=$(git hash-object path1/file1) &&
24 git update-index --add file0 path1/file1 &&
25 tree=$(git write-tree) &&
26 echo "$tree" &&
27 echo nitfol >file0 &&
28 echo yomin >path1/file1 &&
29 after0=$(git hash-object file0) &&
30 after1=$(git hash-object path1/file1) &&
31 git update-index file0 path1/file1'
33 cat >expected <<\EOF
34 EOF
35 test_expect_success \
36 'limit to path should show nothing' \
37 'git diff-index --cached $tree -- path >current &&
38 compare_diff_raw current expected'
40 cat >expected <<EOF
41 :100644 100644 $before1 $after1 M path1/file1
42 EOF
43 test_expect_success \
44 'limit to path1 should show path1/file1' \
45 'git diff-index --cached $tree -- path1 >current &&
46 compare_diff_raw current expected'
48 cat >expected <<EOF
49 :100644 100644 $before1 $after1 M path1/file1
50 EOF
51 test_expect_success \
52 'limit to path1/ should show path1/file1' \
53 'git diff-index --cached $tree -- path1/ >current &&
54 compare_diff_raw current expected'
56 cat >expected <<EOF
57 :100644 100644 $before1 $after1 M path1/file1
58 EOF
59 test_expect_success \
60 '"*file1" should show path1/file1' \
61 'git diff-index --cached $tree -- "*file1" >current &&
62 compare_diff_raw current expected'
64 cat >expected <<EOF
65 :100644 100644 $before0 $after0 M file0
66 EOF
67 test_expect_success \
68 'limit to file0 should show file0' \
69 'git diff-index --cached $tree -- file0 >current &&
70 compare_diff_raw current expected'
72 cat >expected <<\EOF
73 EOF
74 test_expect_success \
75 'limit to file0/ should emit nothing.' \
76 'git diff-index --cached $tree -- file0/ >current &&
77 compare_diff_raw current expected'
79 test_expect_success 'diff-tree pathspec' '
80 tree2=$(git write-tree) &&
81 echo "$tree2" &&
82 git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
83 test_must_be_empty current
86 test_expect_success 'diff-tree with wildcard shows dir also matches' '
87 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
88 echo file0 >expected &&
89 test_cmp expected result
92 test_expect_success 'diff-tree -r with wildcard' '
93 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
94 echo path1/file1 >expected &&
95 test_cmp expected result
98 test_expect_success 'diff-tree with wildcard shows dir also matches' '
99 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
100 echo path1 >expected &&
101 test_cmp expected result
104 test_expect_success 'diff-tree -r with wildcard from beginning' '
105 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
106 echo path1/file1 >expected &&
107 test_cmp expected result
110 test_expect_success 'diff-tree -r with wildcard' '
111 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
112 echo path1/file1 >expected &&
113 test_cmp expected result
116 test_expect_success 'setup submodules' '
117 test_tick &&
118 git init submod &&
119 ( cd submod && test_commit first ) &&
120 git add submod &&
121 git commit -m first &&
122 ( cd submod && test_commit second ) &&
123 git add submod &&
124 git commit -m second
127 test_expect_success 'diff-tree ignores trailing slash on submodule path' '
128 git diff --name-only HEAD^ HEAD submod >expect &&
129 git diff --name-only HEAD^ HEAD submod/ >actual &&
130 test_cmp expect actual &&
131 git diff --name-only HEAD^ HEAD -- submod/whatever >actual &&
132 test_must_be_empty actual
135 test_expect_success 'diff multiple wildcard pathspecs' '
136 mkdir path2 &&
137 echo rezrov >path2/file1 &&
138 git update-index --add path2/file1 &&
139 tree3=$(git write-tree) &&
140 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
141 cat <<-\EOF >expect &&
142 path1/file1
143 path2/file1
145 test_cmp expect actual
148 test_expect_success 'diff-cache ignores trailing slash on submodule path' '
149 git diff --name-only HEAD^ submod >expect &&
150 git diff --name-only HEAD^ submod/ >actual &&
151 test_cmp expect actual
154 test_done