@@ -25,6 +25,8 @@ def branch_a_list(include_branch = nil?)
2525
2626 let ( :provider ) { resource . provider }
2727
28+ let ( :test_includes ) { [ 'file1' , 'path1/' ] }
29+
2830 before :each do
2931 allow ( Puppet ::Util ) . to receive ( :which ) . with ( 'git' ) . and_return ( '/usr/bin/git' )
3032 end
@@ -713,4 +715,64 @@ def branch_a_list(include_branch = nil?)
713715 end
714716 end
715717 end
718+
719+ describe 'includes' do
720+ context 'when with an ensure of bare and includes are defined' do
721+ it 'raises an error when trying to clone a repo with an ensure of bare' do
722+ resource . delete ( :revision )
723+ resource [ :ensure ] = :bare
724+ resource [ :includes ] = test_includes
725+ expect ( provider ) . to receive ( :exec_git ) . with ( 'clone' , '--bare' , resource . value ( :source ) , resource . value ( :path ) )
726+ expect ( provider ) . to receive ( :update_remotes )
727+ expect { provider . create } . to raise_error ( RuntimeError , %r{Cannot set includes on a bare repository} )
728+ end
729+ end
730+
731+ context 'when with an ensure of mirror and includes are defined' do
732+ it 'raises an error when trying to clone a repo with an ensure of mirror' do
733+ resource . delete ( :revision )
734+ resource [ :ensure ] = :mirror
735+ resource [ :includes ] = test_includes
736+ expect ( provider ) . to receive ( :exec_git ) . with ( 'clone' , '--mirror' , resource . value ( :source ) , resource . value ( :path ) )
737+ expect ( provider ) . to receive ( :update_remotes )
738+ expect { provider . create } . to raise_error ( RuntimeError , %r{Cannot set includes on a mirror repository} )
739+ end
740+ end
741+
742+ context 'when with an ensure of present and includes are defined' do
743+ let ( :sparse_checkout_file ) { StringIO . new }
744+
745+ it 'performs a sparse checkout with git >= 2.25.0' do
746+ resource [ :includes ] = test_includes
747+ expect ( Dir ) . to receive ( :chdir ) . with ( '/' ) . once . and_yield
748+ expect ( Dir ) . to receive ( :chdir ) . with ( '/tmp/test' ) . at_least ( :once ) . and_yield
749+ expect ( provider ) . to receive ( :exec_git ) . with ( 'clone' , resource . value ( :source ) , resource . value ( :path ) )
750+ expect ( provider ) . to receive ( :update_remotes )
751+ expect ( provider ) . to receive ( :exec_git ) . with ( '--version' ) . and_return ( '2.36.1' )
752+ expect ( provider ) . to receive ( :exec_git ) . with ( 'sparse-checkout' , 'set' , '--no-cone' , *resource . value ( :includes ) )
753+ expect ( provider ) . to receive ( :exec_git ) . with ( 'checkout' , '--force' , resource . value ( :revision ) )
754+ expect ( provider ) . to receive ( :exec_git ) . with ( 'branch' , '--no-color' , '-a' ) . and_return ( branch_a_list ( resource . value ( :revision ) ) )
755+ expect ( provider ) . to receive ( :update_submodules )
756+ provider . create
757+ end
758+
759+ it 'performs a sparse checkout with git < 2.25.0' do
760+ resource [ :includes ] = test_includes
761+ expect ( Dir ) . to receive ( :chdir ) . with ( '/' ) . once . and_yield
762+ expect ( Dir ) . to receive ( :chdir ) . with ( '/tmp/test' ) . at_least ( :once ) . and_yield
763+ expect ( provider ) . to receive ( :exec_git ) . with ( 'clone' , resource . value ( :source ) , resource . value ( :path ) )
764+ expect ( provider ) . to receive ( :update_remotes )
765+ expect ( provider ) . to receive ( :exec_git ) . with ( '--version' ) . and_return ( '1.8.3.1' )
766+ expect ( provider ) . to receive ( :exec_git ) . with ( 'config' , '--local' , '--bool' , 'core.sparseCheckout' , 'true' )
767+ expect ( File ) . to receive ( :open ) . with ( '.git/info/sparse-checkout' , 'w' ) . and_yield ( sparse_checkout_file )
768+ resource . value ( :includes ) . each do |inc |
769+ expect ( sparse_checkout_file ) . to receive ( :puts ) . with ( inc )
770+ end
771+ expect ( provider ) . to receive ( :exec_git ) . with ( 'checkout' , '--force' , resource . value ( :revision ) )
772+ expect ( provider ) . to receive ( :exec_git ) . with ( 'branch' , '--no-color' , '-a' ) . and_return ( branch_a_list ( resource . value ( :revision ) ) )
773+ expect ( provider ) . to receive ( :update_submodules )
774+ provider . create
775+ end
776+ end
777+ end
716778end
0 commit comments