src/utils/filestree.js
function get(repoState, dirPath) {
    // Remove trailing '/' etc.
    const normDirPath = Path.join(dirPath, '.');
    const filepaths = DirUtils.readFilenamesRecursive(repoState, normDirPath);

    const tree = {
        value: File.createDir(normDirPath),
        children: {}
    };

    for (let i = 0; i < filepaths.length; i++) {
        const relativePath = Path.relative(normDirPath, filepaths[i]);
        const parts = relativePath.split('/');
        let node = tree;
        let prefix = normDirPath;
        for (let j = 0; j < parts.length; j++) {
            const head = parts[j];
            const isLeaf = (j === parts.length - 1);
            prefix = Path.join(prefix, head);

            // Create node if doesn't exist
            if (!node.children[head]) {
                if (isLeaf) {
                    node.children[head] = {
                        value: FileUtils.stat(repoState, filepaths[i])
                    };
                } else {
                    node.children[head] = {
                        value: File.createDir(prefix),
                        children: {}
                    };
                }
            }
            node = node.children[head];
        }
    }

    return TreeNode.fromJS(tree);
}
function get(repoState, dirPath) {
    // Remove trailing '/' etc.
    const normDirPath = Path.join(dirPath, '.');
    const filepaths = DirUtils.readFilenamesRecursive(repoState, normDirPath);

    const tree = {
        value: File.createDir(normDirPath),
        children: {}
    };

    for (let i = 0; i < filepaths.length; i++) {
        const relativePath = Path.relative(normDirPath, filepaths[i]);
        const parts = relativePath.split('/');
        let node = tree;
        let prefix = normDirPath;
        for (let j = 0; j < parts.length; j++) {
            const head = parts[j];
            const isLeaf = (j === parts.length - 1);
            prefix = Path.join(prefix, head);

            // Create node if doesn't exist
            if (!node.children[head]) {
                if (isLeaf) {
                    node.children[head] = {
                        value: FileUtils.stat(repoState, filepaths[i])
                    };
                } else {
                    node.children[head] = {
                        value: File.createDir(prefix),
                        children: {}
                    };
                }
            }
            node = node.children[head];
        }
    }

    return TreeNode.fromJS(tree);
}
Generate a files tree from the current branch, taking pending changes into account.
@param {RepositoryState} repoState
@param {Path} [dir='.'] The directory to get the subtree from, default to root
@return {TreeNode<File>} The directory TreeNode with all its children