@@ -181,9 +181,14 @@ impl GitDatabase {
181
181
. filter ( |co| co. is_fresh ( ) )
182
182
{
183
183
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
+ }
185
190
} ;
186
- checkout . update_submodules ( gctx ) ? ;
191
+
187
192
Ok ( checkout)
188
193
}
189
194
@@ -280,7 +285,7 @@ impl<'a> GitCheckout<'a> {
280
285
database : & ' a GitDatabase ,
281
286
revision : git2:: Oid ,
282
287
gctx : & GlobalContext ,
283
- ) -> CargoResult < GitCheckout < ' a > > {
288
+ ) -> CargoResult < ( GitCheckout < ' a > , CheckoutGuard ) > {
284
289
let dirname = into. parent ( ) . unwrap ( ) ;
285
290
paths:: create_dir_all ( & dirname) ?;
286
291
if into. exists ( ) {
@@ -329,8 +334,8 @@ impl<'a> GitCheckout<'a> {
329
334
let repo = repo. unwrap ( ) ;
330
335
331
336
let checkout = GitCheckout :: new ( database, revision, repo) ;
332
- checkout. reset ( gctx) ?;
333
- Ok ( checkout)
337
+ let guard = checkout. reset ( gctx) ?;
338
+ Ok ( ( checkout, guard ) )
334
339
}
335
340
336
341
/// Checks if the `HEAD` of this checkout points to the expected revision.
@@ -355,10 +360,11 @@ impl<'a> GitCheckout<'a> {
355
360
/// To enable this we have a dummy file in our checkout, [`.cargo-ok`],
356
361
/// which if present means that the repo has been successfully reset and is
357
362
/// 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.
359
365
///
360
366
/// [`.cargo-ok`]: CHECKOUT_READY_LOCK
361
- fn reset ( & self , gctx : & GlobalContext ) -> CargoResult < ( ) > {
367
+ fn reset ( & self , gctx : & GlobalContext ) -> CargoResult < CheckoutGuard > {
362
368
let guard = CheckoutGuard :: guard ( & self . path ) ;
363
369
info ! ( "reset {} to {}" , self . repo. path( ) . display( ) , self . revision) ;
364
370
@@ -370,8 +376,7 @@ impl<'a> GitCheckout<'a> {
370
376
let object = self . repo . find_object ( self . revision , None ) ?;
371
377
reset ( & self . repo , & object, gctx) ?;
372
378
373
- guard. mark_ok ( ) ?;
374
- Ok ( ( ) )
379
+ Ok ( guard)
375
380
}
376
381
377
382
/// Like `git submodule update --recursive` but for this git checkout.
0 commit comments