Skip to content

Commit

Permalink
Merge branch 'main' into integrate-exp-show
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Apr 17, 2023
2 parents 269840a + 8eade5a commit ce57701
Show file tree
Hide file tree
Showing 37 changed files with 657 additions and 150 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## [0.7.7] - 2023-04-17

### 🚀 New Features and Enhancements

- Hidden: Add and remove branches to the experiments table [#3670](https://github.com/iterative/vscode-dvc/pull/3670) by [@sroy3](https://github.com/sroy3)

### 🐛 Bug Fixes

- fix(table): DnD behavior for groups [#3683](https://github.com/iterative/vscode-dvc/pull/3683) by [@shcheklein](https://github.com/shcheklein)
- Do not convert the manually entered path into a relative path [#3686](https://github.com/iterative/vscode-dvc/pull/3686) by [@sroy3](https://github.com/sroy3)

## [0.7.6] - 2023-04-13

### 🐛 Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"extensionDependencies": [
"vscode.git"
],
"version": "0.7.6",
"version": "0.7.7",
"license": "Apache-2.0",
"readme": "./README.md",
"repository": {
Expand Down Expand Up @@ -1653,7 +1653,7 @@
"vscode-languageclient": "8.1.0"
},
"devDependencies": {
"@swc/core": "1.3.46",
"@swc/core": "1.3.49",
"@swc/jest": "0.2.24",
"@types/chai": "4.3.4",
"@types/chai-as-promised": "7.1.5",
Expand Down
2 changes: 2 additions & 0 deletions extension/src/cli/git/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const gitPath = {

export enum Command {
ADD = 'add',
BRANCH = 'branch',
CLEAN = 'clean',
COMMIT = 'commit',
DIFF = 'diff',
Expand All @@ -37,6 +38,7 @@ export enum Flag {
MESSAGE = '-m',
NAME_ONLY = '--name-only',
NO_EMPTY_DIRECTORY = '--no-empty-directory',
NO_MERGE = '--no-merge',
NUMBER = '-n',
PRETTY_FORMAT_COMMIT_MESSAGE = '--pretty=format:%H%n%an%n%ar%nrefNames:%D%nmessage:%B',
OTHERS = '--others',
Expand Down
71 changes: 71 additions & 0 deletions extension/src/cli/git/reader.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { EventEmitter } from 'vscode'
import { Disposable, Disposer } from '@hediet/std/disposable'
import { GitReader } from './reader'
import { CliResult, CliStarted } from '..'
import { createProcess } from '../../process/execution'
import { getMockedProcess } from '../../test/util/jest'

jest.mock('vscode')
jest.mock('@hediet/std/disposable')
jest.mock('fs')
jest.mock('../../process/execution')
jest.mock('../../env')
jest.mock('../../common/logger')

const mockedDisposable = jest.mocked(Disposable)

const mockedCreateProcess = jest.mocked(createProcess)

beforeEach(() => {
jest.resetAllMocks()
})

describe('GitReader', () => {
mockedDisposable.fn.mockReturnValueOnce({
track: function <T>(disposable: T): T {
return disposable
},
untrack: function <T>(disposable: T): T {
return disposable
}
} as unknown as (() => void) & Disposer)

const gitReader = new GitReader({
processCompleted: {
event: jest.fn(),
fire: jest.fn()
} as unknown as EventEmitter<CliResult>,
processStarted: {
event: jest.fn(),
fire: jest.fn()
} as unknown as EventEmitter<CliStarted>
})

describe('getBranches', () => {
it('should match the expected output', async () => {
const cwd = __dirname
const branches = ['main', 'exp-12', 'fix-bug-11', 'other']
mockedCreateProcess.mockReturnValueOnce(
getMockedProcess(branches.join('\n'))
)

const cliOutput = await gitReader.getBranches(cwd)
expect(cliOutput).toStrictEqual(branches)
expect(mockedCreateProcess).toHaveBeenCalledWith({
args: ['branch', '--no-merge'],
cwd,
executable: 'git'
})
})

it('should return an empty array if the cli returns any type of error', async () => {
const cwd = __dirname
mockedCreateProcess.mockImplementationOnce(() => {
throw new Error('unexpected error - something something')
})

const cliOutput = await gitReader.getBranches(cwd)
expect(cliOutput).toStrictEqual([])
})
})
})
13 changes: 12 additions & 1 deletion extension/src/cli/git/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { trimAndSplit } from '../../util/stdout'
import { isDirectory } from '../../fileSystem'

export const autoRegisteredCommands = {
GIT_GET_BRANCHES: 'getBranches',
GIT_GET_COMMIT_MESSAGES: 'getCommitMessages',
GIT_GET_NUM_COMMITS: 'getNumCommits',
GIT_GET_REMOTE_URL: 'getRemoteUrl',
Expand Down Expand Up @@ -88,12 +89,22 @@ export class GitReader extends GitCli {
)
try {
const revisions = await this.executeProcess(options)
return revisions.split('\n').length
return trimAndSplit(revisions).length
} catch {
return ''
}
}

public async getBranches(cwd: string): Promise<string[]> {
const options = getOptions(cwd, Command.BRANCH, Flag.NO_MERGE)
try {
const branches = await this.executeProcess(options)
return trimAndSplit(branches)
} catch {
return []
}
}

private async getUntrackedDirectories(cwd: string): Promise<string[]> {
const options = getOptions(
cwd,
Expand Down
10 changes: 10 additions & 0 deletions extension/src/experiments/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class ExperimentsData extends BaseData<ExpShowOutput> {

void this.watchExpGitRefs()
void this.managedUpdate()
void this.updateAvailableBranchesToSelect()
}

public managedUpdate() {
Expand Down Expand Up @@ -67,6 +68,14 @@ export class ExperimentsData extends BaseData<ExpShowOutput> {
this.collectedFiles = collectFiles(data, this.collectedFiles)
}

private async updateAvailableBranchesToSelect() {
const allBranches = await this.internalCommands.executeCommand<string[]>(
AvailableCommands.GIT_GET_BRANCHES,
this.dvcRoot
)
this.experiments.setAvailableBranchesToShow(allBranches)
}

private async watchExpGitRefs(): Promise<void> {
const gitRoot = await this.internalCommands.executeCommand(
AvailableCommands.GIT_GET_REPOSITORY_ROOT,
Expand All @@ -92,6 +101,7 @@ export class ExperimentsData extends BaseData<ExpShowOutput> {
if (
watchedRelPaths.some(watchedRelPath => path.includes(watchedRelPath))
) {
void this.updateAvailableBranchesToSelect()
return this.managedUpdate()
}
}
Expand Down
8 changes: 8 additions & 0 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export class Experiments extends BaseRepository<TableData> {
private dvcLiveOnlySignalFile: string

private readonly addStage: () => Promise<boolean>
private readonly selectBranches: (
branchesSelected: string[]
) => Promise<string[] | undefined>

constructor(
dvcRoot: string,
Expand All @@ -107,6 +110,9 @@ export class Experiments extends BaseRepository<TableData> {
resourceLocator: ResourceLocator,
workspaceState: Memento,
addStage: () => Promise<boolean>,
selectBranches: (
branchesSelected: string[]
) => Promise<string[] | undefined>,
data?: ExperimentsData
) {
super(dvcRoot, resourceLocator.beaker)
Expand All @@ -118,6 +124,7 @@ export class Experiments extends BaseRepository<TableData> {

this.internalCommands = internalCommands
this.addStage = addStage
this.selectBranches = selectBranches

this.onDidChangeIsParamsFileFocused = this.paramsFileFocused.event
this.onDidChangeExperiments = this.experimentsChanged.event
Expand Down Expand Up @@ -564,6 +571,7 @@ export class Experiments extends BaseRepository<TableData> {
this.dvcRoot
),
() => this.addStage(),
(branchesSelected: string[]) => this.selectBranches(branchesSelected),
() =>
this.internalCommands.executeCommand<number>(
AvailableCommands.GIT_GET_NUM_COMMITS,
Expand Down
31 changes: 31 additions & 0 deletions extension/src/experiments/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class ExperimentsModel extends ModelWithPersistence {
private starredExperiments: StarredExperiments
private numberOfCommitsToShow: number
private isBranchesView: boolean
private branchesToShow: string[] = []
private availableBranchesToShow: string[] = []

private filters: Map<string, FilterDefinition> = new Map()

Expand Down Expand Up @@ -90,6 +92,11 @@ export class ExperimentsModel extends ModelWithPersistence {
DEFAULT_NUM_OF_COMMITS_TO_SHOW
)

this.branchesToShow = this.revive<string[]>(
PersistenceKey.EXPERIMENTS_BRANCHES,
[]
)

const assignedColors = new Set(
Object.values(this.coloredStatus).filter(Boolean)
)
Expand Down Expand Up @@ -403,6 +410,23 @@ export class ExperimentsModel extends ModelWithPersistence {
return this.isBranchesView
}

public setBranchesToShow(branches: string[]) {
this.branchesToShow = branches
this.persistBranchesToShow()
}

public getBranchesToShow() {
return this.branchesToShow
}

public setAvailableBranchesToShow(branches: string[]) {
this.availableBranchesToShow = branches
}

public getAvailableBranchesToShow() {
return this.availableBranchesToShow
}

private findIndexByPath(pathToRemove: string) {
return this.currentSorts.findIndex(({ path }) => path === pathToRemove)
}
Expand Down Expand Up @@ -507,6 +531,13 @@ export class ExperimentsModel extends ModelWithPersistence {
)
}

private persistBranchesToShow() {
return this.persist(
PersistenceKey.EXPERIMENTS_BRANCHES,
this.branchesToShow
)
}

private addDetails(experiment: Experiment) {
const { id } = experiment

Expand Down
1 change: 1 addition & 0 deletions extension/src/experiments/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export type TableData = {
columnWidths: Record<string, number>
filteredCount: number
filters: string[]
hasBranchesToSelect: boolean
hasCheckpoints: boolean
hasColumns: boolean
hasConfig: boolean
Expand Down
23 changes: 23 additions & 0 deletions extension/src/experiments/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export class WebviewMessages {
private isShowingMoreCommits = true

private readonly addStage: () => Promise<boolean>
private readonly selectBranches: (
branchesSelected: string[]
) => Promise<string[] | undefined>

private readonly getNumCommits: () => Promise<number>
private readonly update: () => Promise<void>

Expand All @@ -64,6 +68,9 @@ export class WebviewMessages {
) => Promise<string | undefined>,
hasStages: () => Promise<string>,
addStage: () => Promise<boolean>,
selectBranches: (
branchesSelected: string[]
) => Promise<string[] | undefined>,
getNumCommits: () => Promise<number>,
update: () => Promise<void>
) {
Expand All @@ -76,6 +83,7 @@ export class WebviewMessages {
this.stopQueuedExperiments = stopQueuedExperiments
this.hasStages = hasStages
this.addStage = addStage
this.selectBranches = selectBranches
this.getNumCommits = getNumCommits
this.update = update

Expand Down Expand Up @@ -217,6 +225,8 @@ export class WebviewMessages {

case MessageFromWebviewType.SHOW_LESS_COMMITS:
return this.changeCommitsToShow(-1)
case MessageFromWebviewType.SELECT_BRANCHES:
return this.addAndRemoveBranches()

case MessageFromWebviewType.SWITCH_BRANCHES_VIEW:
return this.switchToBranchesView()
Expand All @@ -229,6 +239,17 @@ export class WebviewMessages {
}
}

private async addAndRemoveBranches() {
const selectedBranches = await this.selectBranches(
this.experiments.getBranchesToShow()
)
if (!selectedBranches) {
return
}
this.experiments.setBranchesToShow(selectedBranches)
await this.update()
}

private async switchToBranchesView() {
this.experiments.setIsBranchesView(true)
await this.update()
Expand Down Expand Up @@ -265,6 +286,8 @@ export class WebviewMessages {
columns: this.columns.getSelected(),
filteredCount: this.experiments.getFilteredCount(),
filters: this.experiments.getFilterPaths(),
hasBranchesToSelect:
this.experiments.getAvailableBranchesToShow().length > 0,
hasCheckpoints: this.experiments.hasCheckpoints(),
hasColumns: this.columns.hasNonDefaultColumns(),
hasConfig: this.hasConfig,
Expand Down
Loading

0 comments on commit ce57701

Please sign in to comment.