Skip to content

Commit 6a649b1

Browse files
authored
Merge pull request #78 from square/tsutton/re-add-shared
Add `--shared` flag when using sparse checkout
2 parents 65716ef + 4e04bf1 commit 6a649b1

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*:lock
22
*.gem
3+
Gemfile.lock

lib/git-fastclone.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ def clone(url, rev, src_dir, config)
253253

254254
clone_commands = ['git', 'clone', verbose ? '--verbose' : '--quiet']
255255
# For sparse checkouts, clone directly from the local mirror and skip the actual checkout process
256+
# --shared is included so that the checkout remains fast even if the reference and destination directories
257+
# live on different filesystem volumes.
256258
# For normal clones, use --reference and clone from the remote URL
257259
if sparse_paths
258-
clone_commands.push('--no-checkout')
260+
clone_commands.push('--no-checkout', '--shared')
259261
clone_commands << mirror.to_s << clone_dest
260262
else
261263
clone_commands << '--reference' << mirror.to_s << url.to_s << clone_dest

lib/git-fastclone/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Version string for git-fastclone
44
module GitFastCloneVersion
5-
VERSION = '1.6.0'
5+
VERSION = '1.6.1'
66
end

spec/git_fastclone_runner_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,47 @@ def create_lockfile_double
145145
end
146146
end
147147

148+
context 'with sparse checkout' do
149+
before(:each) do
150+
subject.sparse_paths = %w[path1 path2]
151+
end
152+
153+
it 'should clone with --no-checkout and --shared flags' do
154+
expect(subject).to receive(:fail_on_error).with(
155+
'git', 'clone', '--quiet', '--no-checkout', '--shared', '/cache', '/pwd/.',
156+
{ quiet: true, print_on_failure: false }
157+
) { runner_execution_double }
158+
expect(subject).to receive(:perform_sparse_checkout).with('/pwd/.', 'PH')
159+
160+
subject.clone(placeholder_arg, 'PH', '.', nil)
161+
end
162+
163+
it 'should clone with verbose mode and --shared flag' do
164+
subject.verbose = true
165+
expect(subject).to receive(:fail_on_error).with(
166+
'git', 'clone', '--verbose', '--no-checkout', '--shared', '/cache', '/pwd/.',
167+
{ quiet: false, print_on_failure: false }
168+
) { runner_execution_double }
169+
expect(subject).to receive(:perform_sparse_checkout).with('/pwd/.', 'PH')
170+
171+
subject.clone(placeholder_arg, 'PH', '.', nil)
172+
end
173+
174+
it 'should not perform regular checkout when sparse checkout is enabled' do
175+
expect(subject).to receive(:fail_on_error).with(
176+
'git', 'clone', '--quiet', '--no-checkout', '--shared', '/cache', '/pwd/.',
177+
{ quiet: true, print_on_failure: false }
178+
) { runner_execution_double }
179+
expect(subject).to receive(:perform_sparse_checkout).with('/pwd/.', 'PH')
180+
expect(subject).not_to receive(:fail_on_error).with(
181+
'git', 'checkout', '--quiet', 'PH',
182+
anything
183+
)
184+
185+
subject.clone(placeholder_arg, 'PH', '.', nil)
186+
end
187+
end
188+
148189
context 'with pre-clone-hook' do
149190
let(:pre_clone_hook) { '/some/command' }
150191
before(:each) do

0 commit comments

Comments
 (0)