@@ -557,17 +557,22 @@ impl Build {
557
557
continue
558
558
}
559
559
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 ) ;
563
568
564
569
match submodule. state {
565
570
State :: MaybeDirty => {
566
571
// drop staged changes
567
- self . run ( git ( ) . current_dir ( submodule . path )
572
+ self . run ( git ( ) . current_dir ( & submodule_path )
568
573
. args ( & [ "reset" , "--hard" ] ) ) ;
569
574
// drops unstaged changes
570
- self . run ( git ( ) . current_dir ( submodule . path )
575
+ self . run ( git ( ) . current_dir ( & submodule_path )
571
576
. args ( & [ "clean" , "-fdx" ] ) ) ;
572
577
} ,
573
578
State :: NotInitialized => {
@@ -577,9 +582,9 @@ impl Build {
577
582
State :: OutOfSync => {
578
583
// drops submodule commits that weren't reported to the (outer) git repository
579
584
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 )
581
586
. args ( & [ "reset" , "--hard" ] ) ) ;
582
- self . run ( git ( ) . current_dir ( submodule . path )
587
+ self . run ( git ( ) . current_dir ( & submodule_path )
583
588
. args ( & [ "clean" , "-fdx" ] ) ) ;
584
589
} ,
585
590
}
0 commit comments