@@ -33,6 +33,25 @@ impl<'repo> Submodule<'repo> {
3333 unsafe { crate :: opt_bytes ( self , raw:: git_submodule_branch ( self . raw ) ) }
3434 }
3535
36+ /// Perform the clone step for a newly created submodule.
37+ ///
38+ /// This performs the necessary `git_clone` to setup a newly-created submodule.
39+ pub fn clone (
40+ & mut self ,
41+ opts : Option < & mut SubmoduleUpdateOptions < ' _ > > ,
42+ ) -> Result < Repository , Error > {
43+ unsafe {
44+ let raw_opts = opts. map ( |o| o. raw ( ) ) ;
45+ let mut raw_repo = ptr:: null_mut ( ) ;
46+ try_call ! ( raw:: git_submodule_clone(
47+ & mut raw_repo,
48+ self . raw,
49+ raw_opts. as_ref( )
50+ ) ) ;
51+ Ok ( Binding :: from_raw ( raw_repo) )
52+ }
53+ }
54+
3655 /// Get the submodule's url.
3756 ///
3857 /// Returns `None` if the url is not valid utf-8 or if the URL isn't present
@@ -360,4 +379,26 @@ mod tests {
360379 t ! ( submodule. update( init, opts) ) ;
361380 }
362381 }
382+
383+ #[ test]
384+ fn clone_submodule ( ) {
385+ // -----------------------------------
386+ // Same as `add_a_submodule()`
387+ let ( _td, repo1) = crate :: test:: repo_init ( ) ;
388+ let ( _td, repo2) = crate :: test:: repo_init ( ) ;
389+ let ( _td, parent) = crate :: test:: repo_init ( ) ;
390+
391+ let url1 = Url :: from_file_path ( & repo1. workdir ( ) . unwrap ( ) ) . unwrap ( ) ;
392+ let url3 = Url :: from_file_path ( & repo2. workdir ( ) . unwrap ( ) ) . unwrap ( ) ;
393+ let mut s1 = parent
394+ . submodule ( & url1. to_string ( ) , Path :: new ( "bar" ) , true )
395+ . unwrap ( ) ;
396+ let mut s2 = parent
397+ . submodule ( & url3. to_string ( ) , Path :: new ( "bar2" ) , true )
398+ . unwrap ( ) ;
399+ // -----------------------------------
400+
401+ t ! ( s1. clone( Some ( & mut SubmoduleUpdateOptions :: default ( ) ) ) ) ;
402+ t ! ( s2. clone( None ) ) ;
403+ }
363404}
0 commit comments