1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
| | #!/bin/sh
test_description='grep in sparse checkout
This test creates a repo with the following structure:
.
|-- a
|-- b
|-- dir
| `-- c
`-- sub
|-- A
| `-- a
`-- B
`-- b
Where . has non-cone mode sparsity patterns and sub is a submodule with cone
mode sparsity patterns. The resulting sparse-checkout should leave the following
structure:
.
|-- a
`-- sub
`-- B
`-- b
'
. ./test-lib.sh
test_expect_success 'setup' '
echo "text" >a &&
echo "text" >b &&
mkdir dir &&
echo "text" >dir/c &&
git init sub &&
(
cd sub &&
mkdir A B &&
echo "text" >A/a &&
echo "text" >B/b &&
git add A B &&
git commit -m sub &&
git sparse-checkout init --cone &&
git sparse-checkout set B
) &&
git submodule add ./sub &&
git add a b dir &&
git commit -m super &&
git sparse-checkout init --no-cone &&
git sparse-checkout set "/*" "!b" "!/*/" &&
git tag -am t-commit t-commit HEAD &&
tree=$(git rev-parse HEAD^{tree}) &&
git tag -am t-tree t-tree $tree &&
test_path_is_missing b &&
test_path_is_missing dir &&
test_path_is_missing sub/A &&
test_path_is_file a &&
test_path_is_file sub/B/b
'
test_expect_success 'grep in working tree should honor sparse checkout' '
cat >expect <<-EOF &&
a:text
EOF
git grep "text" >actual &&
test_cmp expect actual
'
test_expect_success 'grep --cached should honor sparse checkout' '
cat >expect <<-EOF &&
a:text
EOF
git grep --cached "text" >actual &&
test_cmp expect actual
'
test_expect_success 'grep <commit-ish> should honor sparse checkout' '
commit=$(git rev-parse HEAD) &&
cat >expect_commit <<-EOF &&
$commit:a:text
EOF
cat >expect_t-commit <<-EOF &&
t-commit:a:text
EOF
git grep "text" $commit >actual_commit &&
test_cmp expect_commit actual_commit &&
git grep "text" t-commit >actual_t-commit &&
test_cmp expect_t-commit actual_t-commit
'
test_expect_success 'grep <tree-ish> should ignore sparsity patterns' '
commit=$(git rev-parse HEAD) &&
tree=$(git rev-parse HEAD^{tree}) &&
cat >expect_tree <<-EOF &&
$tree:a:text
$tree:b:text
$tree:dir/c:text
EOF
cat >expect_t-tree <<-EOF &&
t-tree:a:text
t-tree:b:text
t-tree:dir/c:text
EOF
git grep "text" $tree >actual_tree &&
test_cmp expect_tree actual_tree &&
git grep "text" t-tree >actual_t-tree &&
test_cmp expect_t-tree actual_t-tree
'
test_expect_success 'grep --recurse-submodules --cached should honor sparse checkout in submodule' '
cat >expect <<-EOF &&
a:text
sub/B/b:text
EOF
git grep --recurse-submodules --cached "text" >actual &&
test_cmp expect actual
'
test_expect_success 'grep --recurse-submodules <commit-ish> should honor sparse checkout in submodule' '
commit=$(git rev-parse HEAD) &&
cat >expect_commit <<-EOF &&
$commit:a:text
$commit:sub/B/b:text
EOF
cat >expect_t-commit <<-EOF &&
t-commit:a:text
t-commit:sub/B/b:text
EOF
git grep --recurse-submodules "text" $commit >actual_commit &&
test_cmp expect_commit actual_commit &&
git grep --recurse-submodules "text" t-commit >actual_t-commit &&
test_cmp expect_t-commit actual_t-commit
'
test_done
|