diff --git a/.gitignore b/.gitignore index 1de17f9..590fd39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *:lock *.gem +Gemfile.lock diff --git a/lib/git-fastclone.rb b/lib/git-fastclone.rb index 876f53a..d55b2e5 100644 --- a/lib/git-fastclone.rb +++ b/lib/git-fastclone.rb @@ -253,9 +253,11 @@ def clone(url, rev, src_dir, config) clone_commands = ['git', 'clone', verbose ? '--verbose' : '--quiet'] # For sparse checkouts, clone directly from the local mirror and skip the actual checkout process + # --shared is included so that the checkout remains fast even if the reference and destination directories + # live on different filesystem volumes. # For normal clones, use --reference and clone from the remote URL if sparse_paths - clone_commands.push('--no-checkout') + clone_commands.push('--no-checkout', '--shared') clone_commands << mirror.to_s << clone_dest else clone_commands << '--reference' << mirror.to_s << url.to_s << clone_dest diff --git a/lib/git-fastclone/version.rb b/lib/git-fastclone/version.rb index eaba986..99c539c 100644 --- a/lib/git-fastclone/version.rb +++ b/lib/git-fastclone/version.rb @@ -2,5 +2,5 @@ # Version string for git-fastclone module GitFastCloneVersion - VERSION = '1.6.0' + VERSION = '1.6.1' end diff --git a/spec/git_fastclone_runner_spec.rb b/spec/git_fastclone_runner_spec.rb index 4bbc641..d8baf4d 100644 --- a/spec/git_fastclone_runner_spec.rb +++ b/spec/git_fastclone_runner_spec.rb @@ -145,6 +145,47 @@ def create_lockfile_double end end + context 'with sparse checkout' do + before(:each) do + subject.sparse_paths = %w[path1 path2] + end + + it 'should clone with --no-checkout and --shared flags' do + expect(subject).to receive(:fail_on_error).with( + 'git', 'clone', '--quiet', '--no-checkout', '--shared', '/cache', '/pwd/.', + { quiet: true, print_on_failure: false } + ) { runner_execution_double } + expect(subject).to receive(:perform_sparse_checkout).with('/pwd/.', 'PH') + + subject.clone(placeholder_arg, 'PH', '.', nil) + end + + it 'should clone with verbose mode and --shared flag' do + subject.verbose = true + expect(subject).to receive(:fail_on_error).with( + 'git', 'clone', '--verbose', '--no-checkout', '--shared', '/cache', '/pwd/.', + { quiet: false, print_on_failure: false } + ) { runner_execution_double } + expect(subject).to receive(:perform_sparse_checkout).with('/pwd/.', 'PH') + + subject.clone(placeholder_arg, 'PH', '.', nil) + end + + it 'should not perform regular checkout when sparse checkout is enabled' do + expect(subject).to receive(:fail_on_error).with( + 'git', 'clone', '--quiet', '--no-checkout', '--shared', '/cache', '/pwd/.', + { quiet: true, print_on_failure: false } + ) { runner_execution_double } + expect(subject).to receive(:perform_sparse_checkout).with('/pwd/.', 'PH') + expect(subject).not_to receive(:fail_on_error).with( + 'git', 'checkout', '--quiet', 'PH', + anything + ) + + subject.clone(placeholder_arg, 'PH', '.', nil) + end + end + context 'with pre-clone-hook' do let(:pre_clone_hook) { '/some/command' } before(:each) do