From 506bb456fa769a4cfb20421bfea1af885ff2106c Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 10 Mar 2020 01:58:45 -0400 Subject: [PATCH] Fixes #970 - Stashes doesn't honor files layout --- src/views/nodes/stashNode.ts | 29 +++++++++++++++++++++++------ src/views/nodes/stashesNode.ts | 6 +++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/views/nodes/stashNode.ts b/src/views/nodes/stashNode.ts index 145a52b..dc1fb6b 100644 --- a/src/views/nodes/stashNode.ts +++ b/src/views/nodes/stashNode.ts @@ -1,20 +1,23 @@ 'use strict'; +import * as paths from 'path'; import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { Container } from '../../container'; import { CommitFormatter, GitStashCommit } from '../../git/gitService'; -import { Iterables } from '../../system'; -import { View } from '../viewBase'; +import { Arrays, Iterables, Strings } from '../../system'; +import { ViewWithFiles } from '../viewBase'; import { StashFileNode } from './stashFileNode'; import { ResourceType, ViewNode, ViewRefNode } from './viewNode'; import { RepositoryNode } from './repositoryNode'; +import { FileNode, FolderNode } from '../nodes'; +import { ViewFilesLayout } from '../../config'; -export class StashNode extends ViewRefNode { +export class StashNode extends ViewRefNode { static key = ':stash'; static getId(repoPath: string, ref: string): string { return `${RepositoryNode.getId(repoPath)}${this.key}(${ref})`; } - constructor(view: View, parent: ViewNode, public readonly commit: GitStashCommit) { + constructor(view: ViewWithFiles, parent: ViewNode, public readonly commit: GitStashCommit) { super(commit.toGitUri(), view, parent); } @@ -48,8 +51,22 @@ export class StashNode extends ViewRefNode { } } - const children = files.map(s => new StashFileNode(this.view, this, s, this.commit.toFileCommit(s))); - children.sort((a, b) => a.label.localeCompare(b.label, undefined, { numeric: true, sensitivity: 'base' })); + let children: FileNode[] = files.map(s => new StashFileNode(this.view, this, s, this.commit.toFileCommit(s))); + if (this.view.config.files.layout !== ViewFilesLayout.List) { + const hierarchy = Arrays.makeHierarchical( + children, + n => n.uri.relativePath.split('/'), + (...parts: string[]) => Strings.normalizePath(paths.join(...parts)), + this.view.config.files.compact + ); + + const root = new FolderNode(this.view, this, this.repoPath, '', hierarchy); + children = root.getChildren() as FileNode[]; + } else { + children.sort((a, b) => + a.label!.localeCompare(b.label!, undefined, { numeric: true, sensitivity: 'base' }) + ); + } return children; } diff --git a/src/views/nodes/stashesNode.ts b/src/views/nodes/stashesNode.ts index af4cc46..d75642f 100644 --- a/src/views/nodes/stashesNode.ts +++ b/src/views/nodes/stashesNode.ts @@ -3,19 +3,19 @@ import { TreeItem, TreeItemCollapsibleState } from 'vscode'; import { Container } from '../../container'; import { GitUri, Repository } from '../../git/gitService'; import { Iterables } from '../../system'; -import { View } from '../viewBase'; +import { ViewWithFiles } from '../viewBase'; import { MessageNode } from './common'; import { StashNode } from './stashNode'; import { ResourceType, ViewNode } from './viewNode'; import { RepositoryNode } from './repositoryNode'; -export class StashesNode extends ViewNode { +export class StashesNode extends ViewNode { static key = ':stashes'; static getId(repoPath: string): string { return `${RepositoryNode.getId(repoPath)}${this.key}`; } - constructor(uri: GitUri, view: View, parent: ViewNode, public readonly repo: Repository) { + constructor(uri: GitUri, view: ViewWithFiles, parent: ViewNode, public readonly repo: Repository) { super(uri, view, parent); }