|
27 | 27 | import java.io.File;
|
28 | 28 | import java.io.IOException;
|
29 | 29 | import java.io.InputStream;
|
| 30 | +import java.lang.reflect.InvocationTargetException; |
30 | 31 | import java.nio.file.Paths;
|
31 | 32 | import java.text.ParseException;
|
32 | 33 | import java.util.Arrays;
|
|
54 | 55 | import org.opengrok.indexer.configuration.CommandTimeoutType;
|
55 | 56 | import org.opengrok.indexer.configuration.RuntimeEnvironment;
|
56 | 57 | import org.opengrok.indexer.util.FileUtilities;
|
| 58 | +import org.opengrok.indexer.util.ForbiddenSymlinkException; |
57 | 59 | import org.opengrok.indexer.util.TestRepository;
|
58 | 60 |
|
59 | 61 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
@@ -209,6 +211,43 @@ public void testDetermineBranchAfterChange() throws Exception {
|
209 | 211 | }
|
210 | 212 | }
|
211 | 213 |
|
| 214 | + @Test |
| 215 | + public void testGetHistoryInBranch() throws Exception { |
| 216 | + // Clone the test repository and create new branch there. |
| 217 | + // Clone under source root to avoid problems with prohibited symlinks. |
| 218 | + File root = new File(repository.getSourceRoot(), "git"); |
| 219 | + File localPath = new File(repository.getSourceRoot(), "gitCloneTestDetermineBranch"); |
| 220 | + GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root); |
| 221 | + String branch; |
| 222 | + String cloneUrl = root.toURI().toString(); |
| 223 | + try (Git gitClone = Git.cloneRepository() |
| 224 | + .setURI(cloneUrl) |
| 225 | + .setDirectory(localPath) |
| 226 | + .call()) { |
| 227 | + |
| 228 | + Ref ref = gitClone.checkout().setCreateBranch(true).setName("foo").call(); |
| 229 | + assertNotNull(ref); |
| 230 | + |
| 231 | + File cloneRoot = gitClone.getRepository().getWorkTree(); |
| 232 | + gitrepo = (GitRepository) RepositoryFactory.getRepository(cloneRoot); |
| 233 | + |
| 234 | + History history = gitrepo.getHistory(cloneRoot); |
| 235 | + assertNotNull(history); |
| 236 | + int numEntries = history.getHistoryEntries().size(); |
| 237 | + assertTrue(numEntries > 0); |
| 238 | + |
| 239 | + RevCommit commit = gitClone.commit(). |
| 240 | + setAuthor( "Snufkin", "[email protected]"). |
| 241 | + setMessage("fresh commit on a new branch").setAllowEmpty(true).call(); |
| 242 | + assertNotNull(commit); |
| 243 | + |
| 244 | + history = gitrepo.getHistory(cloneRoot); |
| 245 | + assertEquals(numEntries + 1, history.getHistoryEntries().size()); |
| 246 | + |
| 247 | + FileUtilities.removeDirs(cloneRoot); |
| 248 | + } |
| 249 | + } |
| 250 | + |
212 | 251 | @Test
|
213 | 252 | public void testDetermineParentEmpty() throws Exception {
|
214 | 253 | File root = new File(repository.getSourceRoot(), "git");
|
@@ -579,6 +618,19 @@ public void testHistory(boolean renamedHandling) throws Exception {
|
579 | 618 | assertEquals(expectedHistory, history);
|
580 | 619 | }
|
581 | 620 |
|
| 621 | + @Test |
| 622 | + public void testSingleHistory() throws Exception { |
| 623 | + RuntimeEnvironment.getInstance().setHandleHistoryOfRenamedFiles(false); |
| 624 | + File root = new File(repository.getSourceRoot(), "git"); |
| 625 | + GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root); |
| 626 | + |
| 627 | + History history = gitrepo.getHistory(new File(root.getAbsolutePath(), "moved2/renamed2.c")); |
| 628 | + assertNotNull(history); |
| 629 | + assertNotNull(history.getHistoryEntries()); |
| 630 | + assertEquals(1, history.getHistoryEntries().size()); |
| 631 | + assertEquals("84599b3c", history.getHistoryEntries().get(0).getRevision()); |
| 632 | + } |
| 633 | + |
582 | 634 | @Test
|
583 | 635 | public void testRenamedSingleHistory() throws Exception {
|
584 | 636 | RuntimeEnvironment.getInstance().setHandleHistoryOfRenamedFiles(true);
|
|
0 commit comments