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

Add commit command #327

Merged
merged 10 commits into from
Apr 27, 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
37 changes: 30 additions & 7 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@
"category": "DVC",
"icon": "$(discard)"
},
{
"title": "%command.commit%",
"command": "dvc.commit",
"category": "DVC",
"icon": "$(check)"
},
{
"title": "%command.commitTarget%",
"command": "dvc.commitTarget",
"category": "DVC",
"icon": "$(check)"
},
{
"title": "%command.pullTarget%",
"command": "dvc.pullTarget",
Expand Down Expand Up @@ -161,6 +173,14 @@
"command": "dvc.checkoutTarget",
"when": "false"
},
{
"command": "dvc.commit",
"when": "false"
},
{
"command": "dvc.commitTarget",
"when": "false"
},
{
"command": "dvc.pullTarget",
"when": "false"
Expand All @@ -170,19 +190,17 @@
"when": "false"
}
],
"scm/change/title": [
{
"command": "dvc.addTarget",
"group": "inline",
"when": "scmProvider == dvc"
}
],
"scm/title": [
{
"command": "dvc.checkout",
"group": "navigation",
"when": "scmProvider == dvc"
},
{
"command": "dvc.commit",
"group": "navigation",
"when": "scmProvider == dvc"
},
{
"command": "dvc.showExperiments",
"group": "experiments",
Expand Down Expand Up @@ -220,6 +238,11 @@
"group": "inline",
"when": "scmProvider == dvc && scmResourceState != untracked && scmResourceState != notInCache"
},
{
"command": "dvc.commitTarget",
"group": "inline",
"when": "scmProvider == dvc"
},
{
"command": "dvc.pushTarget",
"group": "inline",
Expand Down
1 change: 1 addition & 0 deletions extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"command.checkout": "Checkout",
"command.checkoutTarget": "Checkout Target",
"command.commit": "Commit",
"command.commitTarget": "Commit Target",
"command.init": "Init DVC",
"command.initNoScm": "Init DVC --no-scm",
"command.pull": "Pull",
Expand Down
5 changes: 5 additions & 0 deletions extension/src/cli/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum Commands {
ADD = 'add',
CHECKOUT = 'checkout',
COMMIT = 'commit',
EXPERIMENT_GC = 'exp gc -f -w',
EXPERIMENT_QUEUE = 'exp run --queue',
EXPERIMENT_RUN = 'exp run',
Expand All @@ -24,6 +25,10 @@ export enum ListFlag {
RECURSIVE = '-R'
}

export enum CommitFlag {
FORCE = '-f'
}

export enum GcPreserveFlag {
ALL_BRANCHES = '--all-branches',
ALL_TAGS = '--all-tags',
Expand Down
9 changes: 8 additions & 1 deletion extension/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ensureDir } from 'fs-extra'
import { basename, dirname } from 'path'
import { buildCommand, Commands } from './commands'
import { buildCommand, Commands, CommitFlag } from './commands'
import { execProcess } from './execution'

const runTargetCommand = async (
Expand Down Expand Up @@ -28,6 +28,13 @@ export const addTarget = async (options: {
pythonBinPath: string | undefined
}): Promise<string> => runTargetCommand(options, Commands.ADD)

export const commitTarget = (options: {
fsPath: string
cliPath: string | undefined
pythonBinPath: string | undefined
}): Promise<string> =>
runTargetCommand(options, buildCommand(Commands.COMMIT, CommitFlag.FORCE))

export const checkoutTarget = (options: {
fsPath: string
cliPath: string | undefined
Expand Down
27 changes: 27 additions & 0 deletions extension/src/cli/reader.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
checkout,
commit,
experimentApply,
getExperiments,
getRoot,
Expand Down Expand Up @@ -86,6 +87,7 @@ describe('initializeDirectory', () => {
)
})
})

describe('checkout', () => {
it('should call execPromise with the correct parameters', async () => {
const fsPath = __dirname
Expand All @@ -111,6 +113,31 @@ describe('checkout', () => {
})
})

describe('commit', () => {
it('should call execPromise with the correct parameters', async () => {
const cwd = __dirname
const stdout = "Updating lock file 'dvc.lock'"
mockedExecPromise.mockResolvedValueOnce({
stdout,
stderr: ''
})

const output = await commit({
cliPath: 'dvc',
cwd,
pythonBinPath: undefined
})
expect(output).toEqual(stdout)

expect(mockedExecPromise).toBeCalledWith(
'dvc commit -f',
expect.objectContaining({
cwd
})
)
})
})

describe('getRoot', () => {
it('should return the root relative to the cwd', async () => {
const mockRelativeRoot = join('..', '..')
Expand Down
11 changes: 10 additions & 1 deletion extension/src/cli/reader.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { buildCommand, Commands, GcPreserveFlag, ListFlag } from './commands'
import {
buildCommand,
CommitFlag,
Commands,
GcPreserveFlag,
ListFlag
} from './commands'
import { trimAndSplit } from '../util/stdout'
import { ExperimentsRepoJSONOutput } from '../webviews/experiments/contract'
import { execProcess, ReaderOptions } from './execution'

export const checkout = async (options: ReaderOptions): Promise<string[]> =>
execProcess<string[]>(options, Commands.CHECKOUT, trimAndSplit)

export const commit = async (options: ReaderOptions): Promise<string> =>
execProcess<string>(options, buildCommand(Commands.COMMIT, CommitFlag.FORCE))

export const getRoot = async (options: ReaderOptions): Promise<string> =>
execProcess<string>(options, Commands.ROOT)

Expand Down
31 changes: 29 additions & 2 deletions extension/src/cli/register.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { commands } from 'vscode'
import { addTarget, checkoutTarget, pullTarget, pushTarget } from '.'
import {
addTarget,
checkoutTarget,
commitTarget,
pullTarget,
pushTarget
} from '.'
import { Config } from '../Config'
import { Disposer } from '../extension'
import { checkout, initializeDirectory } from './reader'
import { checkout, commit, initializeDirectory } from './reader'
import {
applyExperimentFromQuickPick,
branchExperimentFromQuickPick,
Expand Down Expand Up @@ -51,6 +57,27 @@ const registerCommands = (config: Config, disposer: Disposer) => {
})
)
)

disposer.track(
commands.registerCommand('dvc.commit', ({ rootUri }) => {
commit({
cwd: rootUri.fsPath,
cliPath: config.dvcPath,
pythonBinPath: config.pythonBinPath
})
})
)

disposer.track(
commands.registerCommand('dvc.commitTarget', ({ resourceUri }) =>
commitTarget({
fsPath: resourceUri.fsPath,
cliPath: config.dvcPath,
pythonBinPath: config.pythonBinPath
})
)
)

disposer.track(
commands.registerCommand('dvc.pushTarget', ({ resourceUri }) =>
pushTarget({
Expand Down