git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
1aef0841869b6a98ddd14775d41ee0aee350bd7a blob 7765 bytes (raw)

  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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
 
#!/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
`-- sub2
    `-- a

Where . has non-cone mode sparsity patterns, sub is a submodule with cone mode
sparsity patterns and sub2 is a submodule that is excluded by the superproject
sparsity patterns. The resulting sparse checkout should leave the following
structure on the working tree:

.
|-- a
|-- sub
|   `-- B
|       `-- b
`-- sub2
    `-- a

But note that sub2 should have the SKIP_WORKTREE bit set.
'

. ./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 init sub2 &&
	(
		cd sub2 &&
		echo "text" >a &&
		git add a &&
		git commit -m sub2
	) &&

	git submodule add ./sub &&
	git submodule add ./sub2 &&
	git add a b dir &&
	git commit -m super &&
	git sparse-checkout init --no-cone &&
	git sparse-checkout set "/*" "!b" "!/*/" "sub" &&

	git tag -am tag-to-commit tag-to-commit HEAD &&
	tree=$(git rev-parse HEAD^{tree}) &&
	git tag -am tag-to-tree tag-to-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_path_is_file sub2/a
'

# The two tests bellow check a special case: the sparsity patterns exclude '/b'
# and sparse checkout is enable, but the path exists on the working tree (e.g.
# manually created after `git sparse-checkout init`). In this case, grep should
# skip the file by default, but not with --no-restrict-to-sparse-paths.
test_expect_success 'grep in working tree should honor sparse checkout' '
	cat >expect <<-EOF &&
	a:text
	EOF
	echo "new-text" >b &&
	test_when_finished "rm b" &&
	git grep "text" >actual &&
	test_cmp expect actual
'
test_expect_success 'grep w/ --no-restrict-to-sparse-paths for sparsely excluded but present paths' '
	cat >expect <<-EOF &&
	a:text
	b:new-text
	EOF
	echo "new-text" >b &&
	test_when_finished "rm b" &&
	git --no-restrict-to-sparse-paths 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_tag-to-commit <<-EOF &&
	tag-to-commit:a:text
	EOF
	git grep "text" $commit >actual_commit &&
	test_cmp expect_commit actual_commit &&
	git grep "text" tag-to-commit >actual_tag-to-commit &&
	test_cmp expect_tag-to-commit actual_tag-to-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_tag-to-tree <<-EOF &&
	tag-to-tree:a:text
	tag-to-tree:b:text
	tag-to-tree:dir/c:text
	EOF
	git grep "text" $tree >actual_tree &&
	test_cmp expect_tree actual_tree &&
	git grep "text" tag-to-tree >actual_tag-to-tree &&
	test_cmp expect_tag-to-tree actual_tag-to-tree
'

# Note that sub2/ is present in the worktree but it is excluded by the sparsity
# patterns, so grep should only recurse into it with --no-restrict-to-sparse-paths.
test_expect_success 'grep --recurse-submodules should honor sparse checkout in submodule' '
	cat >expect <<-EOF &&
	a:text
	sub/B/b:text
	EOF
	git grep --recurse-submodules "text" >actual &&
	test_cmp expect actual
'
test_expect_success 'grep --recurse-submodules should search in excluded submodules w/ --no-restrict-to-sparse-paths' '
	cat >expect <<-EOF &&
	a:text
	sub/B/b:text
	sub2/a:text
	EOF
	git --no-restrict-to-sparse-paths grep --recurse-submodules "text" >actual &&
	test_cmp expect actual
'

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_tag-to-commit <<-EOF &&
	tag-to-commit:a:text
	tag-to-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" tag-to-commit >actual_tag-to-commit &&
	test_cmp expect_tag-to-commit actual_tag-to-commit
'

for cmd in 'git --no-restrict-to-sparse-paths grep' \
	   'git -c sparse.restrictCmds=false grep' \
	   'git -c sparse.restrictCmds=true --no-restrict-to-sparse-paths grep'
do

	test_expect_success "$cmd --cached should ignore sparsity patterns" '
		cat >expect <<-EOF &&
		a:text
		b:text
		dir/c:text
		EOF
		$cmd --cached "text" >actual &&
		test_cmp expect actual
	'

	test_expect_success "$cmd <commit-ish> should ignore sparsity patterns" '
		commit=$(git rev-parse HEAD) &&
		cat >expect_commit <<-EOF &&
		$commit:a:text
		$commit:b:text
		$commit:dir/c:text
		EOF
		cat >expect_tag-to-commit <<-EOF &&
		tag-to-commit:a:text
		tag-to-commit:b:text
		tag-to-commit:dir/c:text
		EOF
		$cmd "text" $commit >actual_commit &&
		test_cmp expect_commit actual_commit &&
		$cmd "text" tag-to-commit >actual_tag-to-commit &&
		test_cmp expect_tag-to-commit actual_tag-to-commit
	'
done

test_expect_success 'grep --recurse-submodules --cached \w --no-restrict-to-sparse-paths' '
	cat >expect <<-EOF &&
	a:text
	b:text
	dir/c:text
	sub/A/a:text
	sub/B/b:text
	sub2/a:text
	EOF
	git --no-restrict-to-sparse-paths grep --recurse-submodules --cached \
		"text" >actual &&
	test_cmp expect actual
'

test_expect_success 'grep --recurse-submodules <commit-ish> \w --no-restrict-to-sparse-paths' '
	commit=$(git rev-parse HEAD) &&
	cat >expect_commit <<-EOF &&
	$commit:a:text
	$commit:b:text
	$commit:dir/c:text
	$commit:sub/A/a:text
	$commit:sub/B/b:text
	$commit:sub2/a:text
	EOF
	cat >expect_tag-to-commit <<-EOF &&
	tag-to-commit:a:text
	tag-to-commit:b:text
	tag-to-commit:dir/c:text
	tag-to-commit:sub/A/a:text
	tag-to-commit:sub/B/b:text
	tag-to-commit:sub2/a:text
	EOF
	git --no-restrict-to-sparse-paths grep --recurse-submodules "text" \
		$commit >actual_commit &&
	test_cmp expect_commit actual_commit &&
	git --no-restrict-to-sparse-paths grep --recurse-submodules "text" \
		tag-to-commit >actual_tag-to-commit &&
	test_cmp expect_tag-to-commit actual_tag-to-commit
'

test_expect_success 'should respect the sparse.restrictCmds values from submodules' '
	cat >expect <<-EOF &&
	a:text
	sub/A/a:text
	sub/B/b:text
	EOF
	test_config -C sub sparse.restrictCmds false &&
	git grep --cached --recurse-submodules "text" >actual &&
	test_cmp expect actual
'

test_expect_success 'should propagate --[no]-restrict-to-sparse-paths to submodules' '
	cat >expect <<-EOF &&
	a:text
	b:text
	dir/c:text
	sub/A/a:text
	sub/B/b:text
	sub2/a:text
	EOF
	test_config -C sub sparse.restrictCmds true &&
	git --no-restrict-to-sparse-paths grep --cached --recurse-submodules "text" >actual &&
	test_cmp expect actual
'

for opt in '--untracked' '--no-index'
do
	test_expect_success "--[no]-restrict-to-sparse-paths and $opt are incompatible" "
		test_must_fail git --restrict-to-sparse-paths grep $opt . 2>actual &&
		test_i18ngrep 'restrict-to-sparse-paths is incompatible with' actual
	"
done

test_done
debug log:

solving 1aef084186 ...
found 1aef084186 in https://public-inbox.org/git/748b1e955ccdcf7cd897a180f4b4fe82d7bfcf00.1590627264.git.matheus.bernardino@usp.br/
found ce080cf572 in https://public-inbox.org/git/5ddac818185d316cd5ad9576105f0e4e695b9456.1590627264.git.matheus.bernardino@usp.br/

applying [1/2] https://public-inbox.org/git/5ddac818185d316cd5ad9576105f0e4e695b9456.1590627264.git.matheus.bernardino@usp.br/
diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh
new file mode 100755
index 0000000000..ce080cf572


applying [2/2] https://public-inbox.org/git/748b1e955ccdcf7cd897a180f4b4fe82d7bfcf00.1590627264.git.matheus.bernardino@usp.br/
diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh
index ce080cf572..1aef084186 100755

Checking patch t/t7817-grep-sparse-checkout.sh...
Applied patch t/t7817-grep-sparse-checkout.sh cleanly.
Checking patch t/t7817-grep-sparse-checkout.sh...
Applied patch t/t7817-grep-sparse-checkout.sh cleanly.

index at:
100755 1aef0841869b6a98ddd14775d41ee0aee350bd7a	t/t7817-grep-sparse-checkout.sh

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git