Interested in helping open source friends on HP-UX?
[git/mjg.git] / t / t4010-diff-pathspec.sh
blobbf078418662c4bab4e512be8fc22a5aa76466119
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"/diff-lib.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 git update-index --add file0 path1/file1 &&
21 tree=$(git write-tree) &&
22 echo "$tree" &&
23 echo nitfol >file0 &&
24 echo yomin >path1/file1 &&
25 git update-index file0 path1/file1'
27 cat >expected <<\EOF
28 EOF
29 test_expect_success \
30 'limit to path should show nothing' \
31 'git diff-index --cached $tree -- path >current &&
32 compare_diff_raw current expected'
34 cat >expected <<\EOF
35 :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
36 EOF
37 test_expect_success \
38 'limit to path1 should show path1/file1' \
39 'git diff-index --cached $tree -- path1 >current &&
40 compare_diff_raw current expected'
42 cat >expected <<\EOF
43 :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
44 EOF
45 test_expect_success \
46 'limit to path1/ should show path1/file1' \
47 'git diff-index --cached $tree -- path1/ >current &&
48 compare_diff_raw current expected'
50 cat >expected <<\EOF
51 :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M path1/file1
52 EOF
53 test_expect_success \
54 '"*file1" should show path1/file1' \
55 'git diff-index --cached $tree -- "*file1" >current &&
56 compare_diff_raw current expected'
58 cat >expected <<\EOF
59 :100644 100644 766498d93a4b06057a8e49d23f4068f1170ff38f 0a41e115ab61be0328a19b29f18cdcb49338d516 M file0
60 EOF
61 test_expect_success \
62 'limit to file0 should show file0' \
63 'git diff-index --cached $tree -- file0 >current &&
64 compare_diff_raw current expected'
66 cat >expected <<\EOF
67 EOF
68 test_expect_success \
69 'limit to file0/ should emit nothing.' \
70 'git diff-index --cached $tree -- file0/ >current &&
71 compare_diff_raw current expected'
73 test_expect_success 'diff-tree pathspec' '
74 tree2=$(git write-tree) &&
75 echo "$tree2" &&
76 git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
77 >expected &&
78 test_cmp expected current
81 EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904
83 test_expect_success 'diff-tree with wildcard shows dir also matches' '
84 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
85 echo file0 >expected &&
86 test_cmp expected result
89 test_expect_success 'diff-tree -r with wildcard' '
90 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
91 echo path1/file1 >expected &&
92 test_cmp expected result
95 test_expect_success 'diff-tree with wildcard shows dir also matches' '
96 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
97 echo path1 >expected &&
98 test_cmp expected result
101 test_expect_success 'diff-tree -r with wildcard from beginning' '
102 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
103 echo path1/file1 >expected &&
104 test_cmp expected result
107 test_expect_success 'diff-tree -r with wildcard' '
108 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
109 echo path1/file1 >expected &&
110 test_cmp expected result
113 test_expect_success 'setup submodules' '
114 test_tick &&
115 git init submod &&
116 ( cd submod && test_commit first; ) &&
117 git add submod &&
118 git commit -m first &&
119 ( cd submod && test_commit second; ) &&
120 git add submod &&
121 git commit -m second
124 test_expect_success 'diff-tree ignores trailing slash on submodule path' '
125 git diff --name-only HEAD^ HEAD submod >expect &&
126 git diff --name-only HEAD^ HEAD submod/ >actual &&
127 test_cmp expect actual
130 test_expect_success 'diff multiple wildcard pathspecs' '
131 mkdir path2 &&
132 echo rezrov >path2/file1 &&
133 git update-index --add path2/file1 &&
134 tree3=$(git write-tree) &&
135 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
136 cat <<-\EOF >expect &&
137 path1/file1
138 path2/file1
140 test_cmp expect actual
143 test_expect_success 'diff-cache ignores trailing slash on submodule path' '
144 git diff --name-only HEAD^ submod >expect &&
145 git diff --name-only HEAD^ submod/ >actual &&
146 test_cmp expect actual
149 test_done