@@ -181,9 +181,14 @@ impl GitDatabase {
181181 . filter ( |co| co. is_fresh ( ) )
182182 {
183183 Some ( co) => co,
184- None => GitCheckout :: clone_into ( dest, self , rev, gctx) ?,
184+ None => {
185+ let ( checkout, guard) = GitCheckout :: clone_into ( dest, self , rev, gctx) ?;
186+ checkout. update_submodules ( gctx) ?;
187+ guard. mark_ok ( ) ?;
188+ checkout
189+ }
185190 } ;
186- checkout . update_submodules ( gctx ) ? ;
191+
187192 Ok ( checkout)
188193 }
189194
@@ -280,7 +285,7 @@ impl<'a> GitCheckout<'a> {
280285 database : & ' a GitDatabase ,
281286 revision : git2:: Oid ,
282287 gctx : & GlobalContext ,
283- ) -> CargoResult < GitCheckout < ' a > > {
288+ ) -> CargoResult < ( GitCheckout < ' a > , CheckoutGuard ) > {
284289 let dirname = into. parent ( ) . unwrap ( ) ;
285290 paths:: create_dir_all ( & dirname) ?;
286291 if into. exists ( ) {
@@ -329,8 +334,8 @@ impl<'a> GitCheckout<'a> {
329334 let repo = repo. unwrap ( ) ;
330335
331336 let checkout = GitCheckout :: new ( database, revision, repo) ;
332- checkout. reset ( gctx) ?;
333- Ok ( checkout)
337+ let guard = checkout. reset ( gctx) ?;
338+ Ok ( ( checkout, guard ) )
334339 }
335340
336341 /// Checks if the `HEAD` of this checkout points to the expected revision.
@@ -355,10 +360,11 @@ impl<'a> GitCheckout<'a> {
355360 /// To enable this we have a dummy file in our checkout, [`.cargo-ok`],
356361 /// which if present means that the repo has been successfully reset and is
357362 /// ready to go. Hence if we start to do a reset, we make sure this file
358- /// *doesn't* exist, and then once we're done we create the file.
363+ /// *doesn't* exist. The caller of [`reset`] has an option to perform additional operations
364+ /// (e.g. submodule update) before marking the check-out as ready.
359365 ///
360366 /// [`.cargo-ok`]: CHECKOUT_READY_LOCK
361- fn reset ( & self , gctx : & GlobalContext ) -> CargoResult < ( ) > {
367+ fn reset ( & self , gctx : & GlobalContext ) -> CargoResult < CheckoutGuard > {
362368 let guard = CheckoutGuard :: guard ( & self . path ) ;
363369 info ! ( "reset {} to {}" , self . repo. path( ) . display( ) , self . revision) ;
364370
@@ -370,8 +376,7 @@ impl<'a> GitCheckout<'a> {
370376 let object = self . repo . find_object ( self . revision , None ) ?;
371377 reset ( & self . repo , & object, gctx) ?;
372378
373- guard. mark_ok ( ) ?;
374- Ok ( ( ) )
379+ Ok ( guard)
375380 }
376381
377382 /// Like `git submodule update --recursive` but for this git checkout.
0 commit comments