@@ -557,17 +557,22 @@ impl Build {
557557 continue
558558 }
559559
560- if !submodule. path . exists ( ) {
561- t ! ( fs:: create_dir_all( & submodule. path) ) ;
562- }
560+ // `submodule.path` is the relative path to a submodule (from the repository root)
561+ // `submodule_path` is the path to a submodule from the cwd
562+
563+ // use `submodule.path` when e.g. executing a submodule specific command from the
564+ // repository root
565+ // use `submodule_path` when e.g. executing a normal git command for the submodule
566+ // (set via `current_dir`)
567+ let submodule_path = self . src . join ( submodule. path ) ;
563568
564569 match submodule. state {
565570 State :: MaybeDirty => {
566571 // drop staged changes
567- self . run ( git ( ) . current_dir ( submodule . path )
572+ self . run ( git ( ) . current_dir ( & submodule_path )
568573 . args ( & [ "reset" , "--hard" ] ) ) ;
569574 // drops unstaged changes
570- self . run ( git ( ) . current_dir ( submodule . path )
575+ self . run ( git ( ) . current_dir ( & submodule_path )
571576 . args ( & [ "clean" , "-fdx" ] ) ) ;
572577 } ,
573578 State :: NotInitialized => {
@@ -577,9 +582,9 @@ impl Build {
577582 State :: OutOfSync => {
578583 // drops submodule commits that weren't reported to the (outer) git repository
579584 self . run ( git_submodule ( ) . arg ( "update" ) . arg ( submodule. path ) ) ;
580- self . run ( git ( ) . current_dir ( submodule . path )
585+ self . run ( git ( ) . current_dir ( & submodule_path )
581586 . args ( & [ "reset" , "--hard" ] ) ) ;
582- self . run ( git ( ) . current_dir ( submodule . path )
587+ self . run ( git ( ) . current_dir ( & submodule_path )
583588 . args ( & [ "clean" , "-fdx" ] ) ) ;
584589 } ,
585590 }
0 commit comments