@@ -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