Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework SCM stageModified status #880

Merged
merged 13 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,12 @@
{
"command": "dvc.checkoutTarget",
"group": "inline",
"when": "scmProvider == dvc && scmResourceState != untracked && scmResourceState != notInCache && dvc.commands.available == true"
"when": "scmProvider == dvc && scmResourceGroup == changes && scmResourceState != untracked && scmResourceState != notInCache && dvc.commands.available == true"
},
{
"command": "dvc.commitTarget",
"group": "inline",
"when": "scmProvider == dvc && scmResourceState != untracked && scmResourceState != deleted && dvc.commands.available == true"
"when": "scmProvider == dvc && scmResourceGroup == changes && scmResourceState != untracked && scmResourceState != deleted && dvc.commands.available == true"
}
],
"editor/title": [
Expand Down
6 changes: 3 additions & 3 deletions extension/src/repository/decorationProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,27 @@ describe('DecorationProvider', () => {
const initialState = {
added,
deleted,
gitModified: emptySet,
modified,
notInCache: emptySet,
renamed: emptySet,
stageModified: emptySet,
tracked: emptySet
}

const updatedState = {
added,
deleted,
gitModified: emptySet,
modified: emptySet,
notInCache,
renamed: emptySet,
stageModified: emptySet,
tracked
}

expect(initialState.added).toEqual(updatedState.added)
expect(initialState.deleted).toEqual(updatedState.deleted)
expect(initialState.renamed).toEqual(updatedState.renamed)
expect(initialState.stageModified).toEqual(updatedState.stageModified)
expect(initialState.gitModified).toEqual(updatedState.gitModified)

expect(initialState.modified).not.toEqual(updatedState.modified)
expect(initialState.notInCache).not.toEqual(updatedState.notInCache)
Expand Down
10 changes: 5 additions & 5 deletions extension/src/repository/decorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum Status {
MODIFIED = 'modified',
NOT_IN_CACHE = 'notInCache',
RENAMED = 'renamed',
STAGE_MODIFIED = 'stageModified',
GIT_MODIFIED = 'gitModified',
TRACKED = 'tracked'
}

Expand Down Expand Up @@ -58,10 +58,10 @@ export class DecorationProvider implements FileDecorationProvider {
tooltip: 'DVC renamed'
}

private static DecorationStageModified: FileDecoration = {
private static DecorationGitModified: FileDecoration = {
badge: 'M',
color: new ThemeColor('gitDecoration.stageModifiedResourceForeground'),
tooltip: 'DVC staged modified'
tooltip: 'DVC tracked'
}

private static DecorationTracked: FileDecoration = {
Expand All @@ -80,10 +80,10 @@ export class DecorationProvider implements FileDecorationProvider {
{
added: DecorationProvider.DecorationAdded,
deleted: DecorationProvider.DecorationDeleted,
gitModified: DecorationProvider.DecorationGitModified,
modified: DecorationProvider.DecorationModified,
notInCache: DecorationProvider.DecorationNotInCache,
renamed: DecorationProvider.DecorationRenamed,
stageModified: DecorationProvider.DecorationStageModified
renamed: DecorationProvider.DecorationRenamed
}

constructor(decorationsChanged?: EventEmitter<Uri[]>) {
Expand Down
12 changes: 6 additions & 6 deletions extension/src/repository/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ describe('Repository', () => {
expect.objectContaining({
added: emptySet,
deleted: emptySet,
gitModified: emptySet,
modified,
notInCache: emptySet,
renamed: emptySet,
stageModified: emptySet,
tracked,
untracked
})
Expand Down Expand Up @@ -225,10 +225,10 @@ describe('Repository', () => {
expect(repository.getState()).toEqual({
added: emptySet,
deleted,
gitModified: emptySet,
modified: emptySet,
notInCache: emptySet,
renamed: emptySet,
stageModified: emptySet,
tracked,
untracked: emptySet
})
Expand Down Expand Up @@ -330,10 +330,10 @@ describe('Repository', () => {
expect(repository.getState()).toEqual({
added: emptySet,
deleted,
gitModified: emptySet,
modified,
notInCache,
renamed: emptySet,
stageModified: emptySet,
tracked,
untracked
})
Expand Down Expand Up @@ -425,10 +425,10 @@ describe('Repository', () => {
expect(repository.getState()).toEqual({
added: emptySet,
deleted,
gitModified: emptySet,
modified: emptySet,
notInCache: emptySet,
renamed: emptySet,
stageModified: emptySet,
tracked,
untracked: emptySet
})
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('Repository', () => {
expect(mockedDelay).toBeCalledWith(1000)

const deleted = new Set([join(dvcRoot, model)])
const stageModified = new Set([join(dvcRoot, dataDir)])
const gitModified = new Set([join(dvcRoot, dataDir)])

const tracked = new Set([
resolve(dvcRoot, model),
Expand All @@ -496,10 +496,10 @@ describe('Repository', () => {
expect(repository.getState()).toEqual({
added: emptySet,
deleted,
gitModified,
modified: emptySet,
notInCache: emptySet,
renamed: emptySet,
stageModified,
tracked,
untracked: emptySet
})
Expand Down
11 changes: 4 additions & 7 deletions extension/src/repository/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('RepositoryState', () => {
expect(model.getState()).toEqual({
added: emptySet,
deleted: new Set([join(dvcRoot, deleted)]),
gitModified: new Set([join(dvcRoot, output)]),
modified: new Set([
join(dvcRoot, rawDataDir),
join(dvcRoot, logDir),
Expand All @@ -88,7 +89,6 @@ describe('RepositoryState', () => {
]),
notInCache: emptySet,
renamed: new Set([join(dvcRoot, renamed)]),
stageModified: new Set([join(dvcRoot, output)]),
tracked: new Set([
...list.map(entry => join(dvcRoot, entry.path)),
join(dvcRoot, rawDataDir),
Expand Down Expand Up @@ -121,13 +121,10 @@ describe('RepositoryState', () => {
expect(model.getState()).toEqual({
added: emptySet,
deleted: emptySet,
gitModified: new Set([join(dvcRoot, rawDataDir), join(dvcRoot, data)]),
modified: emptySet,
notInCache: emptySet,
renamed: emptySet,
stageModified: new Set([
join(dvcRoot, rawDataDir),
join(dvcRoot, data)
]),
tracked: new Set([join(dvcRoot, rawDataDir), join(dvcRoot, data)]),
untracked: emptySet
})
Expand Down Expand Up @@ -158,10 +155,10 @@ describe('RepositoryState', () => {
expect(model.getState()).toEqual({
added: emptySet,
deleted: emptySet,
gitModified: emptySet,
modified: new Set([join(dvcRoot, rawDataDir)]),
notInCache: emptySet,
renamed: emptySet,
stageModified: emptySet,
tracked: new Set([join(dvcRoot, rawDataDir), join(dvcRoot, data)]),
untracked: emptySet
})
Expand All @@ -188,10 +185,10 @@ describe('RepositoryState', () => {
expect(model.getState()).toEqual({
added: emptySet,
deleted: emptySet,
gitModified: emptySet,
modified: emptySet,
notInCache: emptySet,
renamed: emptySet,
stageModified: emptySet,
tracked: emptySet,
untracked: emptySet
})
Expand Down
4 changes: 2 additions & 2 deletions extension/src/repository/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class RepositoryModel
private state = {
added: new Set<string>(),
deleted: new Set<string>(),
gitModified: new Set<string>(),
modified: new Set<string>(),
notInCache: new Set<string>(),
renamed: new Set<string>(),
stageModified: new Set<string>(),
tracked: new Set<string>(),
untracked: new Set<string>()
}
Expand Down Expand Up @@ -164,7 +164,7 @@ export class RepositoryModel
const modifiedAgainstCache = this.reduceToModified(statusOutput)
const modifiedAgainstHead = this.mapToTrackedPaths(diffOutput.modified)

this.state.stageModified = this.splitModifiedAgainstHead(
this.state.gitModified = this.splitModifiedAgainstHead(
modifiedAgainstHead,
path => this.pathNotInSet(path, modifiedAgainstCache)
)
Expand Down
5 changes: 4 additions & 1 deletion extension/src/repository/sourceControlManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ describe('SourceControlManagement', () => {
it('should be able to set the state', () => {
const dvcRoot = __dirname
const mockedCreateSourceControl = jest.fn().mockReturnValueOnce({
createResourceGroup: jest.fn().mockReturnValueOnce({}),
createResourceGroup: jest
.fn()
.mockReturnValueOnce({})
.mockReturnValueOnce({}),
inputBox: { visible: true }
})
mockedScm.createSourceControl = mockedCreateSourceControl
Expand Down
52 changes: 34 additions & 18 deletions extension/src/repository/sourceControlManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { basename, extname } from 'path'
import { Disposable } from '@hediet/std/disposable'
import { scm, SourceControlResourceGroup, Uri } from 'vscode'
import { makeObservable, observable } from 'mobx'
import { isStringInEnum } from '../util'

export type SourceControlManagementState = Record<Status, Set<string>>

Expand All @@ -16,7 +15,7 @@ enum Status {
MODIFIED = 'modified',
NOT_IN_CACHE = 'notInCache',
RENAMED = 'renamed',
STAGE_MODIFIED = 'stageModified',
GIT_MODIFIED = 'gitModified',
UNTRACKED = 'untracked'
}

Expand All @@ -26,6 +25,9 @@ export class SourceControlManagement {
@observable
private changedResourceGroup: SourceControlResourceGroup

@observable
private gitModifiedResourceGroup: SourceControlResourceGroup

public readonly dispose = Disposable.fn()

private readonly dvcRoot: string
Expand All @@ -42,15 +44,29 @@ export class SourceControlManagement {
scmView.inputBox.visible = false

this.changedResourceGroup = this.dispose.track(
scmView.createResourceGroup('group1', 'Changes')
scmView.createResourceGroup('changes', 'Changes')
)

this.gitModifiedResourceGroup = this.dispose.track(
scmView.createResourceGroup('gitModified', 'Ready For Git Commit')
)

this.changedResourceGroup.hideWhenEmpty = true
this.gitModifiedResourceGroup.hideWhenEmpty = true

this.setState(state)
}

public setState(state: SourceControlManagementState) {
this.changedResourceGroup.resourceStates = Object.entries(state).reduce(
this.getResourceStatesReducer(),
this.getResourceStatesReducer(
Object.values(Status).filter(status => status !== Status.GIT_MODIFIED)
),
[]
)

this.gitModifiedResourceGroup.resourceStates = Object.entries(state).reduce(
this.getResourceStatesReducer([Status.GIT_MODIFIED]),
[]
)
}
Expand All @@ -59,35 +75,35 @@ export class SourceControlManagement {
return this.changedResourceGroup.resourceStates
}

private getResourceStatesReducer() {
private getResourceStatesReducer(validStatuses: Status[]) {
return (
resourceStates: ResourceState[],
entry: [string, Set<string>]
): ResourceState[] => {
const [status, resources] = entry as [Status, Set<string>]
return [...resourceStates, ...this.getResourceStates(status, resources)]
return [
...resourceStates,
...(validStatuses.includes(status)
? this.getResourceStates(status, resources)
: [])
]
}
}

private isValidStatus(status: string): boolean {
return isStringInEnum(status, Status)
}

private getResourceStates(
contextValue: Status,
paths: Set<string>
): ResourceState[] {
if (!this.isValidStatus(contextValue)) {
return []
}
return [...paths]
.filter(
path => extname(path) !== '.dvc' && basename(path) !== '.gitignore'
)
.map(path => ({
contextValue,
dvcRoot: this.dvcRoot,
resourceUri: Uri.file(path)
}))
.map(path => {
return {
contextValue,
dvcRoot: this.dvcRoot,
resourceUri: Uri.file(path)
}
})
}
}
20 changes: 0 additions & 20 deletions extension/src/util/index.test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions extension/src/util/index.ts

This file was deleted.