|
25 | 25 | package org.opengrok.indexer.history;
|
26 | 26 |
|
27 | 27 | import java.io.File;
|
| 28 | +import java.io.FileWriter; |
28 | 29 | import java.io.IOException;
|
29 | 30 | import java.io.InputStream;
|
| 31 | +import java.io.Writer; |
| 32 | +import java.nio.file.Path; |
30 | 33 | import java.nio.file.Paths;
|
31 | 34 | import java.util.Arrays;
|
32 | 35 | import java.util.Collections;
|
|
38 | 41 | import java.util.stream.Collectors;
|
39 | 42 |
|
40 | 43 | import org.eclipse.jgit.api.Git;
|
| 44 | +import org.eclipse.jgit.lib.Constants; |
41 | 45 | import org.eclipse.jgit.lib.ObjectId;
|
42 | 46 | import org.eclipse.jgit.lib.Ref;
|
43 | 47 | import org.eclipse.jgit.revwalk.RevCommit;
|
@@ -812,14 +816,25 @@ private String addSubmodule(String submoduleName) throws Exception {
|
812 | 816 |
|
813 | 817 | @Test
|
814 | 818 | void testSubmodule() throws Exception {
|
815 |
| - String submodulePath = addSubmodule("submodule"); |
| 819 | + String submoduleOriginPath = addSubmodule("submodule"); |
| 820 | + Path submodulePath = Paths.get(repository.getSourceRoot(), "git", "submodule"); |
816 | 821 |
|
817 |
| - Repository subRepo = RepositoryFactory. |
818 |
| - getRepository(Paths.get(repository.getSourceRoot(), "git", "submodule").toFile()); |
| 822 | + Repository subRepo = RepositoryFactory.getRepository(submodulePath.toFile()); |
| 823 | + assertNotNull(subRepo); |
| 824 | + assertNotNull(subRepo.getParent()); |
| 825 | + assertTrue(subRepo.getParent().contains(submoduleOriginPath)); |
| 826 | + |
| 827 | + // Test relative path too. JGit always writes absolute path so overwrite the contents directly. |
| 828 | + File gitFile = Paths.get(submodulePath.toString(), Constants.DOT_GIT).toFile(); |
| 829 | + assertTrue(gitFile.isFile()); |
| 830 | + try (Writer writer = new FileWriter(gitFile)) { |
| 831 | + writer.write(Constants.GITDIR + ".." + File.separator + Constants.DOT_GIT + |
| 832 | + File.separator + Constants.MODULES + File.separator + "submodule"); |
| 833 | + } |
| 834 | + subRepo = RepositoryFactory.getRepository(submodulePath.toFile()); |
819 | 835 | assertNotNull(subRepo);
|
820 | 836 | assertNotNull(subRepo.getParent());
|
821 |
| - assertTrue(subRepo.getParent().contains(submodulePath)); |
822 | 837 |
|
823 |
| - // TODO: test relative path too |
| 838 | + // TODO: cleanup |
824 | 839 | }
|
825 | 840 | }
|
0 commit comments