Fix file browser for directories two levels deep
TreeWalk was only entering exact-match subtrees, missing intermediate directories. Now enters all subtrees that are prefix of the target path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -464,12 +464,14 @@ public class GitService
|
||||
if (dirPath != null && !dirPath.isEmpty())
|
||||
{
|
||||
tw.setFilter(PathFilter.create(dirPath));
|
||||
// Walk into the directory
|
||||
// Walk into the directory, entering intermediate subtrees as needed
|
||||
while (tw.next())
|
||||
{
|
||||
if (tw.isSubtree() && tw.getPathString().equals(dirPath))
|
||||
if (tw.isSubtree())
|
||||
{
|
||||
String path = tw.getPathString();
|
||||
tw.enterSubtree();
|
||||
if (path.equals(dirPath))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,6 +373,23 @@ class GitServiceTest
|
||||
assertTrue(files.stream().anyMatch(f -> f.path().equals("README.md")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listFilesAtCommitReturnsNestedDirectoryContents() throws GitAPIException, IOException
|
||||
{
|
||||
gitService.cloneRepository(bareRemote.toUri().toString(), "myrepo");
|
||||
// Create a file two levels deep: src/main/Hello.txt
|
||||
Path srcMain = worktreePath.resolve("myrepo/src/main");
|
||||
Files.createDirectories(srcMain);
|
||||
Files.writeString(srcMain.resolve("Hello.txt"), "hello");
|
||||
gitService.stageFiles("myrepo", List.of("src/main/Hello.txt"));
|
||||
gitService.commit("myrepo", "Add nested file");
|
||||
|
||||
var commits = gitService.listCommits("myrepo");
|
||||
var files = gitService.listFilesAtCommit("myrepo", commits.getFirst().hash(), "src/main");
|
||||
assertFalse(files.isEmpty());
|
||||
assertTrue(files.stream().anyMatch(f -> f.path().equals("src/main/Hello.txt")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getFileContentAtCommitReturnsContent() throws GitAPIException, IOException
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user