git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
8509694bf1f42a8e92689dfcc8e82fa8b872d9bb blob 5197 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
 
#!/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
'

# 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
# honor --restrict-to-sparse-paths.
test_expect_success 'grep in working tree should honor sparse checkout' '
	cat >expect <<-EOF &&
	a:text
	EOF
	echo newtext >b &&
	git grep "text" >actual &&
	test_cmp expect actual &&
	rm b
'
test_expect_success 'grep w/ --no-restrict-to-sparse-paths for sparsely excluded but present paths' '
	cat >expect <<-EOF &&
	a:text
	b:newtext
	EOF
	echo newtext >b &&
	git --no-restrict-to-sparse-paths grep "text" >actual &&
	test_cmp expect actual &&
	rm b
'

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
'

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_t-commit <<-EOF &&
		t-commit:a:text
		t-commit:b:text
		t-commit:dir/c:text
		EOF
		$cmd "text" $commit >actual_commit &&
		test_cmp expect_commit actual_commit &&
		$cmd "text" t-commit >actual_t-commit &&
		test_cmp expect_t-commit actual_t-commit
	'
done

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
	git -C sub config sparse.restrictCmds false &&
	git grep --cached --recurse-submodules "text" >actual &&
	test_cmp expect actual &&
	git -C sub config --unset sparse.restrictCmds
'

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
	EOF
	git -C sub config sparse.restrictCmds true &&
	git --no-restrict-to-sparse-paths grep --cached --recurse-submodules "text" >actual &&
	test_cmp expect actual &&
	git -C sub config --unset sparse.restrictCmds
'

test_done
debug log:

solving 8509694bf1 ...
found 8509694bf1 in https://public-inbox.org/git/3e9e90624901113fd5c5670c0c2023c709f71d6d.1589058209.git.matheus.bernardino@usp.br/
found 3bd67082eb in https://public-inbox.org/git/e00674c7278b032b826110f33e25a5dee176c7ba.1589058209.git.matheus.bernardino@usp.br/

applying [1/2] https://public-inbox.org/git/e00674c7278b032b826110f33e25a5dee176c7ba.1589058209.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..3bd67082eb


applying [2/2] https://public-inbox.org/git/3e9e90624901113fd5c5670c0c2023c709f71d6d.1589058209.git.matheus.bernardino@usp.br/
diff --git a/t/t7817-grep-sparse-checkout.sh b/t/t7817-grep-sparse-checkout.sh
index 3bd67082eb..8509694bf1 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 8509694bf1f42a8e92689dfcc8e82fa8b872d9bb	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