@@ -520,34 +520,34 @@ impl Build {
520
520
return ;
521
521
}
522
522
523
- // check_submodule
524
- let checked_out_hash =
525
- output ( Command :: new ( "git" ) . args ( [ "rev-parse" , "HEAD" ] ) . current_dir ( & absolute_path) ) ;
526
- // update_submodules
527
- let recorded = output (
528
- Command :: new ( "git" )
529
- . args ( [ "ls-tree" , "HEAD" ] )
530
- . arg ( relative_path)
531
- . current_dir ( & self . config . src ) ,
532
- ) ;
523
+ let mut submodule_git = absolute_path;
524
+ submodule_git. push ( ".git" ) ;
525
+ let submodule_git = move || {
526
+ let mut cmd = Command :: new ( "git" ) ;
527
+ // We use `--git-dir` instead of `current_dir` since in a commit hook,
528
+ // some env var is set that makes `current_dir` not have any effect.
529
+ // See <https://github.com/rust-lang/rust/issues/125954>.
530
+ cmd. arg ( "--git-dir" ) . arg ( & submodule_git) ;
531
+ cmd
532
+ } ;
533
+
534
+ // Determine commit checked out in submodule.
535
+ let checked_out_hash = output ( submodule_git ( ) . args ( [ "rev-parse" , "HEAD" ] ) ) ;
536
+ let checked_out_hash = checked_out_hash. trim_end ( ) ;
537
+ // Determine commit that the submodule *should* have.
538
+ let recorded = output ( self . config . git ( ) . args ( [ "ls-tree" , "HEAD" ] ) . arg ( relative_path) ) ;
533
539
let actual_hash = recorded
534
540
. split_whitespace ( )
535
541
. nth ( 2 )
536
542
. unwrap_or_else ( || panic ! ( "unexpected output `{}`" , recorded) ) ;
537
543
538
- // update_submodule
539
- if actual_hash == checked_out_hash. trim_end ( ) {
544
+ if actual_hash == checked_out_hash {
540
545
// already checked out
541
546
return ;
542
547
}
543
548
544
549
println ! ( "Updating submodule {}" , relative_path. display( ) ) ;
545
- self . run (
546
- Command :: new ( "git" )
547
- . args ( [ "submodule" , "-q" , "sync" ] )
548
- . arg ( relative_path)
549
- . current_dir ( & self . config . src ) ,
550
- ) ;
550
+ self . run ( self . config . git ( ) . args ( [ "submodule" , "-q" , "sync" ] ) . arg ( relative_path) ) ;
551
551
552
552
// Try passing `--progress` to start, then run git again without if that fails.
553
553
let update = |progress : bool | {
@@ -590,26 +590,22 @@ impl Build {
590
590
// Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
591
591
// diff-index reports the modifications through the exit status
592
592
let has_local_modifications = !self . run_cmd (
593
- BootstrapCommand :: from (
594
- Command :: new ( "git" )
595
- . args ( [ "diff-index" , "--quiet" , "HEAD" ] )
596
- . current_dir ( & absolute_path) ,
597
- )
598
- . allow_failure ( )
599
- . output_mode ( match self . is_verbose ( ) {
600
- true => OutputMode :: PrintAll ,
601
- false => OutputMode :: PrintOutput ,
602
- } ) ,
593
+ BootstrapCommand :: from ( submodule_git ( ) . args ( [ "diff-index" , "--quiet" , "HEAD" ] ) )
594
+ . allow_failure ( )
595
+ . output_mode ( match self . is_verbose ( ) {
596
+ true => OutputMode :: PrintAll ,
597
+ false => OutputMode :: PrintOutput ,
598
+ } ) ,
603
599
) ;
604
600
if has_local_modifications {
605
- self . run ( Command :: new ( "git" ) . args ( [ "stash" , "push" ] ) . current_dir ( & absolute_path ) ) ;
601
+ self . run ( submodule_git ( ) . args ( [ "stash" , "push" ] ) ) ;
606
602
}
607
603
608
- self . run ( Command :: new ( "git" ) . args ( [ "reset" , "-q" , "--hard" ] ) . current_dir ( & absolute_path ) ) ;
609
- self . run ( Command :: new ( "git" ) . args ( [ "clean" , "-qdfx" ] ) . current_dir ( & absolute_path ) ) ;
604
+ self . run ( submodule_git ( ) . args ( [ "reset" , "-q" , "--hard" ] ) ) ;
605
+ self . run ( submodule_git ( ) . args ( [ "clean" , "-qdfx" ] ) ) ;
610
606
611
607
if has_local_modifications {
612
- self . run ( Command :: new ( "git" ) . args ( [ "stash" , "pop" ] ) . current_dir ( absolute_path ) ) ;
608
+ self . run ( submodule_git ( ) . args ( [ "stash" , "pop" ] ) ) ;
613
609
}
614
610
}
615
611
0 commit comments