@@ -520,19 +520,20 @@ impl Build {
520520 return ;
521521 }
522522
523- // check_submodule
524- let checked_out_hash =
525- output ( helpers:: git ( Some ( & absolute_path) ) . args ( [ "rev-parse" , "HEAD" ] ) ) ;
526- // update_submodules
523+ let submodule_git = || helpers:: git ( Some ( & absolute_path) ) ;
524+
525+ // Determine commit checked out in submodule.
526+ let checked_out_hash = output ( submodule_git ( ) . args ( [ "rev-parse" , "HEAD" ] ) ) ;
527+ let checked_out_hash = checked_out_hash. trim_end ( ) ;
528+ // Determine commit that the submodule *should* have.
527529 let recorded =
528530 output ( helpers:: git ( Some ( & self . src ) ) . args ( [ "ls-tree" , "HEAD" ] ) . arg ( relative_path) ) ;
529531 let actual_hash = recorded
530532 . split_whitespace ( )
531533 . nth ( 2 )
532534 . unwrap_or_else ( || panic ! ( "unexpected output `{}`" , recorded) ) ;
533535
534- // update_submodule
535- if actual_hash == checked_out_hash. trim_end ( ) {
536+ if actual_hash == checked_out_hash {
536537 // already checked out
537538 return ;
538539 }
@@ -581,26 +582,22 @@ impl Build {
581582 // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
582583 // diff-index reports the modifications through the exit status
583584 let has_local_modifications = !self . run_cmd (
584- BootstrapCommand :: from ( helpers:: git ( Some ( & absolute_path) ) . args ( [
585- "diff-index" ,
586- "--quiet" ,
587- "HEAD" ,
588- ] ) )
589- . allow_failure ( )
590- . output_mode ( match self . is_verbose ( ) {
591- true => OutputMode :: PrintAll ,
592- false => OutputMode :: PrintOutput ,
593- } ) ,
585+ BootstrapCommand :: from ( submodule_git ( ) . args ( [ "diff-index" , "--quiet" , "HEAD" ] ) )
586+ . allow_failure ( )
587+ . output_mode ( match self . is_verbose ( ) {
588+ true => OutputMode :: PrintAll ,
589+ false => OutputMode :: PrintOutput ,
590+ } ) ,
594591 ) ;
595592 if has_local_modifications {
596- self . run ( helpers :: git ( Some ( & absolute_path ) ) . args ( [ "stash" , "push" ] ) ) ;
593+ self . run ( submodule_git ( ) . args ( [ "stash" , "push" ] ) ) ;
597594 }
598595
599- self . run ( helpers :: git ( Some ( & absolute_path ) ) . args ( [ "reset" , "-q" , "--hard" ] ) ) ;
600- self . run ( helpers :: git ( Some ( & absolute_path ) ) . args ( [ "clean" , "-qdfx" ] ) ) ;
596+ self . run ( submodule_git ( ) . args ( [ "reset" , "-q" , "--hard" ] ) ) ;
597+ self . run ( submodule_git ( ) . args ( [ "clean" , "-qdfx" ] ) ) ;
601598
602599 if has_local_modifications {
603- self . run ( helpers :: git ( Some ( & absolute_path ) ) . args ( [ "stash" , "pop" ] ) ) ;
600+ self . run ( submodule_git ( ) . args ( [ "stash" , "pop" ] ) ) ;
604601 }
605602 }
606603
0 commit comments