Skip to content

Commit c12a639

Browse files
authored
Show dvc root if there is only a single nested root inside of the project (#1952)
1 parent 5c88657 commit c12a639

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

extension/src/fileSystem/tree.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { basename, join } from 'path'
1+
import { basename, join, resolve } from 'path'
22
import { commands, EventEmitter, TreeItem, Uri, window } from 'vscode'
33
import { Disposable, Disposer } from '@hediet/std/disposable'
44
import { exists, isDirectory } from '.'
55
import { TrackedExplorerTree } from './tree'
6+
import { getWorkspaceFolders } from '../vscode/workspaceFolders'
67
import { InternalCommands } from '../commands/internal'
78
import { RegisteredCommands } from '../commands/external'
89
import { OutputChannel } from '../vscode/outputChannel'
@@ -44,10 +45,13 @@ const mockedInternalCommands = new InternalCommands({
4445
const mockedExists = jest.mocked(exists)
4546
const mockedIsDirectory = jest.mocked(isDirectory)
4647

48+
const mockedGetWorkspaceFolders = jest.mocked(getWorkspaceFolders)
49+
4750
jest.mock('vscode')
4851
jest.mock('@hediet/std/disposable')
4952
jest.mock('.')
5053
jest.mock('../cli/reader')
54+
jest.mock('../vscode/workspaceFolders')
5155

5256
beforeEach(() => {
5357
jest.resetAllMocks()
@@ -102,8 +106,33 @@ describe('TrackedTreeView', () => {
102106
expect(mockedGetChildren).toBeCalledTimes(0)
103107
})
104108

109+
it('should return the single dvc root if it is nested', async () => {
110+
const mockedDvcRoots = [dvcDemoPath]
111+
mockedGetWorkspaceFolders.mockReturnValueOnce([
112+
resolve(dvcDemoPath, '..')
113+
])
114+
115+
const trackedTreeView = new TrackedExplorerTree(
116+
mockedInternalCommands,
117+
mockedRepositories
118+
)
119+
trackedTreeView.initialize(mockedDvcRoots)
120+
121+
const rootElements = await trackedTreeView.getChildren()
122+
123+
expect(rootElements).toStrictEqual([
124+
{
125+
dvcRoot: dvcDemoPath,
126+
isDirectory: true,
127+
isTracked: true,
128+
resourceUri: Uri.file(dvcDemoPath)
129+
}
130+
])
131+
})
132+
105133
it('should return directories first in the list of root items', async () => {
106134
const mockedDvcRoots = [dvcDemoPath]
135+
mockedGetWorkspaceFolders.mockReturnValueOnce(mockedDvcRoots)
107136

108137
const trackedTreeView = new TrackedExplorerTree(
109138
mockedInternalCommands,
@@ -150,6 +179,7 @@ describe('TrackedTreeView', () => {
150179

151180
it('should get the children for the provided element', async () => {
152181
const data = Uri.file(join(dvcDemoPath, 'data'))
182+
mockedGetWorkspaceFolders.mockReturnValueOnce([dvcDemoPath])
153183

154184
const trackedTreeView = new TrackedExplorerTree(
155185
mockedInternalCommands,

extension/src/fileSystem/tree.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
Uri
1010
} from 'vscode'
1111
import { exists, relativeWithUri } from '.'
12+
import { standardizePath } from './path'
1213
import { fireWatcher } from './watcher'
1314
import { deleteTarget, moveTargets } from './workspace'
14-
import { definedAndNonEmpty, uniqueValues } from '../util/array'
15+
import { definedAndNonEmpty, sameContents, uniqueValues } from '../util/array'
1516
import {
1617
AvailableCommands,
1718
CommandId,
@@ -35,6 +36,7 @@ import {
3536
import { Title } from '../vscode/title'
3637
import { Disposable } from '../class/dispose'
3738
import { createTreeView } from '../vscode/tree'
39+
import { getWorkspaceFolders } from '../vscode/workspaceFolders'
3840

3941
export class TrackedExplorerTree
4042
extends Disposable
@@ -121,7 +123,13 @@ export class TrackedExplorerTree
121123
this.viewed = true
122124
}
123125

124-
if (this.dvcRoots.length === 1) {
126+
if (
127+
this.dvcRoots.length === 1 &&
128+
sameContents(
129+
getWorkspaceFolders(),
130+
this.dvcRoots.map(dvcRoot => standardizePath(dvcRoot))
131+
)
132+
) {
125133
const [onlyRoot] = this.dvcRoots
126134
return this.getRepoChildren(onlyRoot)
127135
}

0 commit comments

Comments
 (0)