@@ -680,49 +680,24 @@ private String getGitDirValue(File dotGit) {
680
680
}
681
681
682
682
private org .eclipse .jgit .lib .Repository getJGitRepository (String directory ) throws IOException {
683
- File dotGit = Paths .get (directory , Constants .DOT_GIT ).toFile ();
684
- if (dotGit .isDirectory ()) {
685
- return FileRepositoryBuilder .create (dotGit );
683
+ File dotGitFile = Paths .get (directory , Constants .DOT_GIT ).toFile ();
684
+ if (dotGitFile .isDirectory ()) {
685
+ return FileRepositoryBuilder .create (dotGitFile );
686
686
}
687
687
688
- // Assume this is a sub-module so dotGit is a file.
688
+ // Assume this is a sub-module so dotGitFile is a file.
689
689
String gitDirValue ;
690
- if ((gitDirValue = getGitDirValue (dotGit )) == null ) {
691
- throw new IOException ("cannot get gitDir value from " + dotGit );
690
+ if ((gitDirValue = getGitDirValue (dotGitFile )) == null ) {
691
+ throw new IOException ("cannot get gitDir value from " + dotGitFile );
692
692
}
693
693
694
- int dotGitIndex = gitDirValue .indexOf (Constants .DOT_GIT );
695
- if (dotGitIndex == -1 ) {
696
- throw new IOException ("no .git in " + gitDirValue );
694
+ // If the gitDir value is relative path, make it absolute. This is necessary for the
695
+ File gitDirFile = new File (gitDirValue );
696
+ if (!gitDirFile .isAbsolute ()) {
697
+ gitDirFile = new File (directory , gitDirValue );
697
698
}
698
699
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 );
708
- }
709
-
710
- parentAbsPath = parentAbsPath .substring (0 , indexDotGitParent );
711
- if (!directory .startsWith (parentAbsPath )) {
712
- throw new IOException (directory + " does not start with " + parentAbsPath );
713
- }
714
- }
715
-
716
- // Assumes directory is canonical path too.
717
- String directoryRelative = directory .substring (parentAbsPath .length () + 1 );
718
-
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 );
723
- }
724
-
725
- return SubmoduleWalk .getSubmoduleRepository (parentRepository , directoryRelative );
700
+ return new FileRepositoryBuilder ().setWorkTree (new File (directory )).setGitDir (gitDirFile ).build ();
726
701
}
727
702
728
703
private void rebuildTagList (File directory ) {
0 commit comments