]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - t/t4010-diff-pathspec.sh
The seventh batch
[thirdparty/git.git] / t / t4010-diff-pathspec.sh
... / ...
CommitLineData
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
13. ./test-lib.sh
14. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
15
16test_expect_success \
17 setup \
18 'echo frotz >file0 &&
19 mkdir path1 &&
20 echo rezrov >path1/file1 &&
21 before0=$(git hash-object file0) &&
22 before1=$(git hash-object path1/file1) &&
23 git update-index --add file0 path1/file1 &&
24 tree=$(git write-tree) &&
25 echo "$tree" &&
26 echo nitfol >file0 &&
27 echo yomin >path1/file1 &&
28 after0=$(git hash-object file0) &&
29 after1=$(git hash-object path1/file1) &&
30 git update-index file0 path1/file1'
31
32cat >expected <<\EOF
33EOF
34test_expect_success \
35 'limit to path should show nothing' \
36 'git diff-index --cached $tree -- path >current &&
37 compare_diff_raw current expected'
38
39cat >expected <<EOF
40:100644 100644 $before1 $after1 M path1/file1
41EOF
42test_expect_success \
43 'limit to path1 should show path1/file1' \
44 'git diff-index --cached $tree -- path1 >current &&
45 compare_diff_raw current expected'
46
47cat >expected <<EOF
48:100644 100644 $before1 $after1 M path1/file1
49EOF
50test_expect_success \
51 'limit to path1/ should show path1/file1' \
52 'git diff-index --cached $tree -- path1/ >current &&
53 compare_diff_raw current expected'
54
55cat >expected <<EOF
56:100644 100644 $before1 $after1 M path1/file1
57EOF
58test_expect_success \
59 '"*file1" should show path1/file1' \
60 'git diff-index --cached $tree -- "*file1" >current &&
61 compare_diff_raw current expected'
62
63cat >expected <<EOF
64:100644 100644 $before0 $after0 M file0
65EOF
66test_expect_success \
67 'limit to file0 should show file0' \
68 'git diff-index --cached $tree -- file0 >current &&
69 compare_diff_raw current expected'
70
71cat >expected <<\EOF
72EOF
73test_expect_success \
74 'limit to file0/ should emit nothing.' \
75 'git diff-index --cached $tree -- file0/ >current &&
76 compare_diff_raw current expected'
77
78test_expect_success 'diff-tree pathspec' '
79 tree2=$(git write-tree) &&
80 echo "$tree2" &&
81 git diff-tree -r --name-only $tree $tree2 -- pa path1/a >current &&
82 test_must_be_empty current
83'
84
85test_expect_success 'diff-tree with wildcard shows dir also matches' '
86 git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result &&
87 echo file0 >expected &&
88 test_cmp expected result
89'
90
91test_expect_success 'diff-tree -r with wildcard' '
92 git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result &&
93 echo path1/file1 >expected &&
94 test_cmp expected result
95'
96
97test_expect_success 'diff-tree with wildcard shows dir also matches' '
98 git diff-tree --name-only $tree $tree2 -- "path1/f*" >result &&
99 echo path1 >expected &&
100 test_cmp expected result
101'
102
103test_expect_success 'diff-tree -r with wildcard from beginning' '
104 git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result &&
105 echo path1/file1 >expected &&
106 test_cmp expected result
107'
108
109test_expect_success 'diff-tree -r with wildcard' '
110 git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result &&
111 echo path1/file1 >expected &&
112 test_cmp expected result
113'
114
115test_expect_success 'setup submodules' '
116 test_tick &&
117 git init submod &&
118 ( cd submod && test_commit first ) &&
119 git add submod &&
120 git commit -m first &&
121 ( cd submod && test_commit second ) &&
122 git add submod &&
123 git commit -m second
124'
125
126test_expect_success 'diff-tree ignores trailing slash on submodule path' '
127 git diff --name-only HEAD^ HEAD submod >expect &&
128 git diff --name-only HEAD^ HEAD submod/ >actual &&
129 test_cmp expect actual &&
130 git diff --name-only HEAD^ HEAD -- submod/whatever >actual &&
131 test_must_be_empty actual
132'
133
134test_expect_success 'diff multiple wildcard pathspecs' '
135 mkdir path2 &&
136 echo rezrov >path2/file1 &&
137 git update-index --add path2/file1 &&
138 tree3=$(git write-tree) &&
139 git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual &&
140 cat <<-\EOF >expect &&
141 path1/file1
142 path2/file1
143 EOF
144 test_cmp expect actual
145'
146
147test_expect_success 'diff-cache ignores trailing slash on submodule path' '
148 git diff --name-only HEAD^ submod >expect &&
149 git diff --name-only HEAD^ submod/ >actual &&
150 test_cmp expect actual
151'
152
153test_done