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,13 +464,15 @@ public class GitService
|
|||||||
if (dirPath != null && !dirPath.isEmpty())
|
if (dirPath != null && !dirPath.isEmpty())
|
||||||
{
|
{
|
||||||
tw.setFilter(PathFilter.create(dirPath));
|
tw.setFilter(PathFilter.create(dirPath));
|
||||||
// Walk into the directory
|
// Walk into the directory, entering intermediate subtrees as needed
|
||||||
while (tw.next())
|
while (tw.next())
|
||||||
{
|
{
|
||||||
if (tw.isSubtree() && tw.getPathString().equals(dirPath))
|
if (tw.isSubtree())
|
||||||
{
|
{
|
||||||
|
String path = tw.getPathString();
|
||||||
tw.enterSubtree();
|
tw.enterSubtree();
|
||||||
break;
|
if (path.equals(dirPath))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -373,6 +373,23 @@ class GitServiceTest
|
|||||||
assertTrue(files.stream().anyMatch(f -> f.path().equals("README.md")));
|
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
|
@Test
|
||||||
void getFileContentAtCommitReturnsContent() throws GitAPIException, IOException
|
void getFileContentAtCommitReturnsContent() throws GitAPIException, IOException
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user