]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4010-diff-pathspec.sh
The third batch
[thirdparty/git.git] / t / t4010-diff-pathspec.sh
CommitLineData
66204988
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Pathspec restrictions
7
8Prepare:
9 file0
10 path1/file1
11'
16d4bd4f
ÆAB
12
13TEST_PASSES_SANITIZE_LEAK=true
66204988 14. ./test-lib.sh
ebd73f50 15. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
66204988
JH
16
17test_expect_success \
18 setup \
19 'echo frotz >file0 &&
20 mkdir path1 &&
21 echo rezrov >path1/file1 &&
32a67072 22 before0=$(git hash-object file0) &&
23 before1=$(git hash-object path1/file1) &&
5be60078 24 git update-index --add file0 path1/file1 &&
38b2e5d1 25 tree=$(git write-tree) &&
66204988
JH
26 echo "$tree" &&
27 echo nitfol >file0 &&
28 echo yomin >path1/file1 &&
32a67072 29 after0=$(git hash-object file0) &&
30 after1=$(git hash-object path1/file1) &&
5be60078 31 git update-index file0 path1/file1'
66204988
JH
32
33cat >expected <<\EOF
34EOF
35test_expect_success \
36 'limit to path should show nothing' \
5be60078 37 'git diff-index --cached $tree -- path >current &&
66204988
JH
38 compare_diff_raw current expected'
39
32a67072 40cat >expected <<EOF
41:100644 100644 $before1 $after1 M path1/file1
66204988
JH
42EOF
43test_expect_success \
44 'limit to path1 should show path1/file1' \
5be60078 45 'git diff-index --cached $tree -- path1 >current &&
66204988
JH
46 compare_diff_raw current expected'
47
32a67072 48cat >expected <<EOF
49:100644 100644 $before1 $after1 M path1/file1
66204988
JH
50EOF
51test_expect_success \
52 'limit to path1/ should show path1/file1' \
5be60078 53 'git diff-index --cached $tree -- path1/ >current &&
66204988
JH
54 compare_diff_raw current expected'
55
32a67072 56cat >expected <<EOF
57:100644 100644 $before1 $after1 M path1/file1
4838237c
NTND
58EOF
59test_expect_success \
60 '"*file1" should show path1/file1' \
61 'git diff-index --cached $tree -- "*file1" >current &&
62 compare_diff_raw current expected'
63
32a67072 64cat >expected <<EOF
65:100644 100644 $before0 $after0 M file0
66204988
JH
66EOF
67test_expect_success \
68 'limit to file0 should show file0' \
5be60078 69 'git diff-index --cached $tree -- file0 >current &&
66204988
JH
70 compare_diff_raw current expected'
71
72cat >expected <<\EOF
73EOF
74test_expect_success \
75 'limit to file0/ should emit nothing.' \
5be60078 76 'git diff-index --cached $tree -- file0/ >current &&
66204988
JH
77 compare_diff_raw current expected'
78
f0946cb8
BS
79test_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 &&
d3c6751b 83 test_must_be_empty current
f0946cb8
BS
84'
85
d38f2809
NTND
86test_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
90'
91
92test_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
96'
97
f1a2ddbb
NTND
98test_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
102'
103
104test_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
108'
109
110test_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
114'
115
74b4f7f2
NTND
116test_expect_success 'setup submodules' '
117 test_tick &&
118 git init submod &&
02779185 119 ( cd submod && test_commit first ) &&
74b4f7f2
NTND
120 git add submod &&
121 git commit -m first &&
02779185 122 ( cd submod && test_commit second ) &&
74b4f7f2
NTND
123 git add submod &&
124 git commit -m second
125'
126
127test_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 &&
35a9f1e9
SG
130 test_cmp expect actual &&
131 git diff --name-only HEAD^ HEAD -- submod/whatever >actual &&
132 test_must_be_empty actual
74b4f7f2
NTND
133'
134
e4ddb057
AS
135test_expect_success 'diff multiple wildcard pathspecs' '
136 mkdir path2 &&
137 echo rezrov >path2/file1 &&
138 git update-index --add path2/file1 &&
38b2e5d1 139 tree3=$(git write-tree) &&
e4ddb057
AS
140 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
141 cat <<-\EOF >expect &&
142 path1/file1
143 path2/file1
144 EOF
145 test_cmp expect actual
146'
147
ae8d0824
NTND
148test_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
152'
153
66204988 154test_done