@@ -25,6 +25,8 @@ def branch_a_list(include_branch = nil?)
25
25
26
26
let ( :provider ) { resource . provider }
27
27
28
+ let ( :test_includes ) { [ 'file1' , 'path1/' ] }
29
+
28
30
before :each do
29
31
allow ( Puppet ::Util ) . to receive ( :which ) . with ( 'git' ) . and_return ( '/usr/bin/git' )
30
32
end
@@ -713,4 +715,65 @@ def branch_a_list(include_branch = nil?)
713
715
end
714
716
end
715
717
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 when includes are defined' 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 ( :sparse_checkout_configured? ) . and_return false
767
+ expect ( provider ) . to receive ( :exec_git ) . with ( 'config' , '--local' , '--bool' , 'core.sparseCheckout' , 'true' )
768
+ expect ( File ) . to receive ( :open ) . with ( File . join ( resource . value ( :path ) , '.git/info/sparse-checkout' ) , 'w' ) . and_yield ( sparse_checkout_file )
769
+ resource . value ( :includes ) . each do |inc |
770
+ expect ( sparse_checkout_file ) . to receive ( :puts ) . with ( inc )
771
+ end
772
+ expect ( provider ) . to receive ( :exec_git ) . with ( 'checkout' , '--force' , resource . value ( :revision ) )
773
+ expect ( provider ) . to receive ( :exec_git ) . with ( 'branch' , '--no-color' , '-a' ) . and_return ( branch_a_list ( resource . value ( :revision ) ) )
774
+ expect ( provider ) . to receive ( :update_submodules )
775
+ provider . create
776
+ end
777
+ end
778
+ end
716
779
end
0 commit comments