@@ -683,48 +683,46 @@ private org.eclipse.jgit.lib.Repository getJGitRepository(String directory) thro
683
683
File dotGit = Paths .get (directory , Constants .DOT_GIT ).toFile ();
684
684
if (dotGit .isDirectory ()) {
685
685
return FileRepositoryBuilder .create (dotGit );
686
- } else if (dotGit .isFile ()) {
687
- // Assume this is a sub-module.
688
- String gitDirValue ;
689
- if ((gitDirValue = getGitDirValue (dotGit )) == null ) {
690
- return null ;
691
- }
686
+ }
692
687
693
- int dotGitIndex = gitDirValue .indexOf (Constants .DOT_GIT );
694
- if (dotGitIndex == -1 ) {
695
- return null ;
696
- }
688
+ // Assume this is a sub-module so dotGit is a file.
689
+ String gitDirValue ;
690
+ if ((gitDirValue = getGitDirValue (dotGit )) == null ) {
691
+ throw new IOException ("cannot get gitDir value from " + dotGit );
692
+ }
697
693
698
- String parentAbsPath ;
699
- if (Paths .get (gitDirValue ).isAbsolute ()) {
700
- parentAbsPath = gitDirValue .substring (0 , dotGitIndex - 1 );
701
- } else {
702
- File parent = new File (directory , gitDirValue .substring (0 , dotGitIndex + Constants .DOT_GIT .length ()));
703
- parentAbsPath = parent .getCanonicalPath ();
704
- int indexDotGitParent = parentAbsPath .indexOf (File .separator + Constants .DOT_GIT );
705
- if (indexDotGitParent == -1 ) {
706
- return null ;
707
- }
694
+ int dotGitIndex = gitDirValue .indexOf (Constants .DOT_GIT );
695
+ if (dotGitIndex == -1 ) {
696
+ throw new IOException ("no .git in " + gitDirValue );
697
+ }
708
698
709
- parentAbsPath = parentAbsPath .substring (0 , indexDotGitParent );
710
- if (!directory .startsWith (parentAbsPath )) {
711
- return null ;
712
- }
699
+ String parentAbsPath ;
700
+ if (Paths .get (gitDirValue ).isAbsolute ()) {
701
+ parentAbsPath = gitDirValue .substring (0 , dotGitIndex - 1 );
702
+ } else {
703
+ File parent = new File (directory , gitDirValue .substring (0 , dotGitIndex + Constants .DOT_GIT .length ()));
704
+ parentAbsPath = parent .getCanonicalPath ();
705
+ int indexDotGitParent = parentAbsPath .indexOf (File .separator + Constants .DOT_GIT );
706
+ if (indexDotGitParent == -1 ) {
707
+ throw new IOException ("not .git in " + parentAbsPath );
713
708
}
714
709
715
- // Assumes directory is canonical path too.
716
- String directoryRelative = directory .substring (parentAbsPath .length () + 1 );
717
-
718
- Repository parentRepository = FileRepositoryBuilder .
719
- create (Paths .get (parentAbsPath , Constants .DOT_GIT ).toFile ());
720
- if (parentRepository == null ) {
721
- return null ;
710
+ parentAbsPath = parentAbsPath .substring (0 , indexDotGitParent );
711
+ if (!directory .startsWith (parentAbsPath )) {
712
+ throw new IOException (directory + " does not start with " + parentAbsPath );
722
713
}
714
+ }
715
+
716
+ // Assumes directory is canonical path too.
717
+ String directoryRelative = directory .substring (parentAbsPath .length () + 1 );
723
718
724
- return SubmoduleWalk .getSubmoduleRepository (parentRepository , directoryRelative );
719
+ Repository parentRepository = FileRepositoryBuilder .
720
+ create (Paths .get (parentAbsPath , Constants .DOT_GIT ).toFile ());
721
+ if (parentRepository == null ) {
722
+ throw new IOException ("cannot create parent repository from " + parentAbsPath );
725
723
}
726
724
727
- return null ;
725
+ return SubmoduleWalk . getSubmoduleRepository ( parentRepository , directoryRelative ) ;
728
726
}
729
727
730
728
private void rebuildTagList (File directory ) {
0 commit comments