diff --git a/extension/src/repository/commands/register.ts b/extension/src/repository/commands/register.ts index 6434bd9aed..1dd407dbfa 100644 --- a/extension/src/repository/commands/register.ts +++ b/extension/src/repository/commands/register.ts @@ -1,3 +1,4 @@ +import { commands } from 'vscode' import { getResourceCommand, getRootCommand, @@ -5,6 +6,7 @@ import { Resource, Root } from '.' +import { tryThenMaybeForce } from '../../cli/actions' import { RegisteredCliCommands } from '../../commands/external' import { AvailableCommands, InternalCommands } from '../../commands/internal' @@ -33,7 +35,12 @@ const registerRootCommands = (internalCommands: InternalCommands) => { internalCommands.registerExternalCliCommand( RegisteredCliCommands.COMMIT, - getRootCommand(internalCommands, AvailableCommands.COMMIT) + async ({ rootUri }) => { + const cwd = rootUri.fsPath + + await tryThenMaybeForce(internalCommands, AvailableCommands.COMMIT, cwd) + return commands.executeCommand('workbench.scm.focus') + } ) internalCommands.registerExternalCliCommand( diff --git a/extension/src/test/suite/repository/sourceControlManagement.test.ts b/extension/src/test/suite/repository/sourceControlManagement.test.ts index 5455ef976a..854a48e94a 100644 --- a/extension/src/test/suite/repository/sourceControlManagement.test.ts +++ b/extension/src/test/suite/repository/sourceControlManagement.test.ts @@ -1,7 +1,7 @@ import { join } from 'path' import { afterEach, beforeEach, describe, it, suite } from 'mocha' import { expect } from 'chai' -import { stub, restore } from 'sinon' +import { stub, restore, spy } from 'sinon' import { window, commands, Uri, MessageItem } from 'vscode' import { Disposable } from '../../../extension' import { CliExecutor } from '../../../cli/executor' @@ -85,12 +85,15 @@ suite('Source Control Management Test Suite', () => { expect(mockCheckout).to.be.calledWith(dvcDemoPath, relPath, '-f') }) - it('should be able to run dvc.commit without error', async () => { + it('should focus the git commit text input box after running dvc commit', async () => { const mockCommit = stub(CliExecutor.prototype, 'commit').resolves('') + const executeCommandSpy = spy(commands, 'executeCommand') await commands.executeCommand(RegisteredCliCommands.COMMIT, { rootUri }) expect(mockCommit).to.be.calledOnce + expect(executeCommandSpy).to.be.calledTwice + expect(executeCommandSpy).to.be.calledWith('workbench.scm.focus') }) it('should prompt to force if dvc.commit fails', async () => {