]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4010-diff-pathspec.sh
Merge branch 'bc/hash-independent-tests-part-6'
[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'
12. ./test-lib.sh
bfdbee98 13. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
66204988
JH
14
15test_expect_success \
16 setup \
17 'echo frotz >file0 &&
18 mkdir path1 &&
19 echo rezrov >path1/file1 &&
32a67072 20 before0=$(git hash-object file0) &&
21 before1=$(git hash-object path1/file1) &&
5be60078 22 git update-index --add file0 path1/file1 &&
38b2e5d1 23 tree=$(git write-tree) &&
66204988
JH
24 echo "$tree" &&
25 echo nitfol >file0 &&
26 echo yomin >path1/file1 &&
32a67072 27 after0=$(git hash-object file0) &&
28 after1=$(git hash-object path1/file1) &&
5be60078 29 git update-index file0 path1/file1'
66204988
JH
30
31cat >expected <<\EOF
32EOF
33test_expect_success \
34 'limit to path should show nothing' \
5be60078 35 'git diff-index --cached $tree -- path >current &&
66204988
JH
36 compare_diff_raw current expected'
37
32a67072 38cat >expected <<EOF
39:100644 100644 $before1 $after1 M path1/file1
66204988
JH
40EOF
41test_expect_success \
42 'limit to path1 should show path1/file1' \
5be60078 43 'git diff-index --cached $tree -- path1 >current &&
66204988
JH
44 compare_diff_raw current expected'
45
32a67072 46cat >expected <<EOF
47:100644 100644 $before1 $after1 M path1/file1
66204988
JH
48EOF
49test_expect_success \
50 'limit to path1/ should show path1/file1' \
5be60078 51 'git diff-index --cached $tree -- path1/ >current &&
66204988
JH
52 compare_diff_raw current expected'
53
32a67072 54cat >expected <<EOF
55:100644 100644 $before1 $after1 M path1/file1
4838237c
NTND
56EOF
57test_expect_success \
58 '"*file1" should show path1/file1' \
59 'git diff-index --cached $tree -- "*file1" >current &&
60 compare_diff_raw current expected'
61
32a67072 62cat >expected <<EOF
63:100644 100644 $before0 $after0 M file0
66204988
JH
64EOF
65test_expect_success \
66 'limit to file0 should show file0' \
5be60078 67 'git diff-index --cached $tree -- file0 >current &&
66204988
JH
68 compare_diff_raw current expected'
69
70cat >expected <<\EOF
71EOF
72test_expect_success \
73 'limit to file0/ should emit nothing.' \
5be60078 74 'git diff-index --cached $tree -- file0/ >current &&
66204988
JH
75 compare_diff_raw current expected'
76
f0946cb8
BS
77test_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 &&
d3c6751b 81 test_must_be_empty current
f0946cb8
BS
82'
83
d38f2809
NTND
84test_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
88'
89
90test_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
94'
95
f1a2ddbb
NTND
96test_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
100'
101
102test_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
106'
107
108test_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
112'
113
74b4f7f2
NTND
114test_expect_success 'setup submodules' '
115 test_tick &&
116 git init submod &&
02779185 117 ( cd submod && test_commit first ) &&
74b4f7f2
NTND
118 git add submod &&
119 git commit -m first &&
02779185 120 ( cd submod && test_commit second ) &&
74b4f7f2
NTND
121 git add submod &&
122 git commit -m second
123'
124
125test_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'
130
e4ddb057
AS
131test_expect_success 'diff multiple wildcard pathspecs' '
132 mkdir path2 &&
133 echo rezrov >path2/file1 &&
134 git update-index --add path2/file1 &&
38b2e5d1 135 tree3=$(git write-tree) &&
e4ddb057
AS
136 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
137 cat <<-\EOF >expect &&
138 path1/file1
139 path2/file1
140 EOF
141 test_cmp expect actual
142'
143
ae8d0824
NTND
144test_expect_success 'diff-cache ignores trailing slash on submodule path' '
145 git diff --name-only HEAD^ submod >expect &&
146 git diff --name-only HEAD^ submod/ >actual &&
147 test_cmp expect actual
148'
149
66204988 150test_done