@@ -453,13 +453,7 @@ public void Submodules_Errors()
453453 var repository = new GitRepository ( GitEnvironment . Empty , GitConfig . Empty , gitDir . Path , gitDir . Path , workingDir . Path ) ;
454454
455455 var submodules = repository . GetSubmodules ( ) ;
456- AssertEx . Equal ( new [ ]
457- {
458- "S10: 'sub10' 'http://github.com'" ,
459- "S11: 'sub11' 'http://github.com'" ,
460- "S6: 'sub6' 'http://github.com'" ,
461- "S9: 'sub9' 'http://github.com'"
462- } , submodules . Select ( s => $ "{ s . Name } : '{ s . WorkingDirectoryRelativePath } ' '{ s . Url } '") ) ;
456+ Assert . Empty ( submodules ) ;
463457
464458 var diagnostics = repository . GetSubmoduleDiagnostics ( ) ;
465459 AssertEx . Equal ( new [ ]
@@ -468,12 +462,6 @@ public void Submodules_Errors()
468462 string . Format ( Resources . InvalidSubmodulePath , "S1" , " " ) ,
469463 // The path of submodule 'S2' is missing or invalid: ''
470464 string . Format ( Resources . InvalidSubmodulePath , "S2" , "" ) ,
471- // Could not find a part of the path 'sub3\.git'.
472- TestUtilities . GetExceptionMessage ( ( ) => File . ReadAllText ( Path . Combine ( workingDir . Path , "sub3" , ".git" ) ) ) ,
473- // Could not find a part of the path 'sub4\.git'.
474- TestUtilities . GetExceptionMessage ( ( ) => File . ReadAllText ( Path . Combine ( workingDir . Path , "sub4" , ".git" ) ) ) ,
475- // Could not find a part of the path 'sub5\.git'.
476- TestUtilities . GetExceptionMessage ( ( ) => File . ReadAllText ( Path . Combine ( workingDir . Path , "sub5" , ".git" ) ) ) ,
477465 // The format of the file 'sub7\.git' is invalid.
478466 string . Format ( Resources . FormatOfFileIsInvalid , Path . Combine ( workingDir . Path , "sub7" , ".git" ) ) ,
479467 // Path specified in file 'sub8\.git' is invalid.
@@ -514,8 +502,8 @@ public void GetSubmoduleHeadCommitSha()
514502 submoduleRefsHeadsDir . CreateFile ( "master" ) . WriteAllText ( "0000000000000000000000000000000000000000" ) ;
515503 submoduleGitDir . CreateFile ( "HEAD" ) . WriteAllText ( "ref: refs/heads/master" ) ;
516504
517- var repository = new GitRepository ( GitEnvironment . Empty , GitConfig . Empty , gitDir . Path , gitDir . Path , workingDir . Path ) ;
518- Assert . Equal ( "0000000000000000000000000000000000000000" , repository . ReadSubmoduleHeadCommitSha ( submoduleWorkingDir . Path ) ) ;
505+ Assert . Equal ( "0000000000000000000000000000000000000000" ,
506+ GitRepository . GetSubmoduleReferenceResolver ( submoduleWorkingDir . Path ) ? . ResolveHeadReference ( ) ) ;
519507 }
520508
521509 [ Fact ]
@@ -534,8 +522,22 @@ public void GetOldStyleSubmoduleHeadCommitSha()
534522 oldStyleSubmoduleRefsHeadDir . CreateFile ( "branch1" ) . WriteAllText ( "1111111111111111111111111111111111111111" ) ;
535523 oldStyleSubmoduleGitDir . CreateFile ( "HEAD" ) . WriteAllText ( "ref: refs/heads/branch1" ) ;
536524
537- var repository = new GitRepository ( GitEnvironment . Empty , GitConfig . Empty , gitDir . Path , gitDir . Path , workingDir . Path ) ;
538- Assert . Equal ( "1111111111111111111111111111111111111111" , repository . ReadSubmoduleHeadCommitSha ( oldStyleSubmoduleWorkingDir . Path ) ) ;
525+ Assert . Equal ( "1111111111111111111111111111111111111111" ,
526+ GitRepository . GetSubmoduleReferenceResolver ( oldStyleSubmoduleWorkingDir . Path ) ? . ResolveHeadReference ( ) ) ;
527+ }
528+
529+ [ Fact ]
530+ public void GetSubmoduleHeadCommitSha_NoGitFile ( )
531+ {
532+ using var temp = new TempRoot ( ) ;
533+
534+ var gitDir = temp . CreateDirectory ( ) ;
535+ var workingDir = temp . CreateDirectory ( ) ;
536+
537+ var submoduleGitDir = temp . CreateDirectory ( ) ;
538+ var submoduleWorkingDir = workingDir . CreateDirectory ( "sub" ) . CreateDirectory ( "abc" ) ;
539+
540+ Assert . Null ( GitRepository . GetSubmoduleReferenceResolver ( submoduleWorkingDir . Path ) ? . ResolveHeadReference ( ) ) ;
539541 }
540542 }
541543}
0 commit comments