Skip to content

Commit

Permalink
rearrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Sep 30, 2021
1 parent fe4b14e commit f75f24b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
10 changes: 5 additions & 5 deletions extension/src/repository/commands/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ const registerRootCommands = (internalCommands: InternalCommands) => {
getRootCommand(internalCommands, AvailableCommands.CHECKOUT)
)

internalCommands.registerExternalCommand<Root>(
RegisteredCommands.RESET_WORKSPACE,
getResetRootCommand(internalCommands)
)

internalCommands.registerExternalCliCommand<Root>(
RegisteredCliCommands.COMMIT,
getRootCommand(internalCommands, AvailableCommands.COMMIT)
Expand All @@ -54,6 +49,11 @@ const registerRootCommands = (internalCommands: InternalCommands) => {
RegisteredCliCommands.PUSH,
getRootCommand(internalCommands, AvailableCommands.PUSH)
)

internalCommands.registerExternalCommand<Root>(
RegisteredCommands.RESET_WORKSPACE,
getResetRootCommand(internalCommands)
)
}

export const registerRepositoryCommands = (
Expand Down
92 changes: 46 additions & 46 deletions extension/src/test/suite/repository/sourceControlManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,6 @@ suite('Source Control Management Test Suite', () => {
expect(mockAdd).to.be.calledOnce
})

it('should not reset the workspace if the user does not confirm', async () => {
const mockCheckout = stub(CliExecutor.prototype, 'checkout').resolves('')
const mockGitReset = stub(ProcessExecution, 'executeProcess').resolves('')

const mockShowWarningMessage = stub(
window,
'showWarningMessage'
).resolves('' as unknown as MessageItem)

await commands.executeCommand(RegisteredCommands.RESET_WORKSPACE, {
rootUri
})

expect(mockShowWarningMessage).to.be.calledOnce
expect(mockCheckout).not.to.be.called
expect(mockGitReset).not.to.be.called
})

it('should not prompt to force if dvc.checkout fails without a prompt error', async () => {
const mockCheckout = stub(CliExecutor.prototype, 'checkout').rejects(
'This is not a error that we would ask the user if they want to try and force'
Expand All @@ -72,34 +54,6 @@ suite('Source Control Management Test Suite', () => {
expect(mockCheckout).to.be.calledWith(rootUri.fsPath)
})

it('should reset the workspace if the user confirms they want to', async () => {
const mockCheckout = stub(CliExecutor.prototype, 'checkout').resolves('')
const mockGitReset = stub(ProcessExecution, 'executeProcess').resolves('')

const mockShowWarningMessage = stub(
window,
'showWarningMessage'
).resolves('Discard Changes' as unknown as MessageItem)

await commands.executeCommand(RegisteredCommands.RESET_WORKSPACE, {
rootUri
})

expect(mockShowWarningMessage).to.be.calledOnce
expect(mockCheckout).to.be.calledOnce
expect(mockGitReset).to.be.calledTwice
expect(mockGitReset).to.be.calledWith({
args: ['reset', '--hard', 'HEAD'],
cwd: dvcDemoPath,
executable: 'git'
})
expect(mockGitReset).to.be.calledWith({
args: ['clean', '-f', '-d', '-q'],
cwd: dvcDemoPath,
executable: 'git'
})
})

it('should be able to run dvc.checkoutTarget without error', async () => {
const mockCheckout = stub(CliExecutor.prototype, 'checkout').resolves('')

Expand Down Expand Up @@ -226,5 +180,51 @@ suite('Source Control Management Test Suite', () => {
expect(mockPush).to.be.calledOnce
expect(mockShowErrorMessage).to.be.calledOnce
})

it('should not reset the workspace if the user does not confirm', async () => {
const mockCheckout = stub(CliExecutor.prototype, 'checkout').resolves('')
const mockGitReset = stub(ProcessExecution, 'executeProcess').resolves('')

const mockShowWarningMessage = stub(
window,
'showWarningMessage'
).resolves('' as unknown as MessageItem)

await commands.executeCommand(RegisteredCommands.RESET_WORKSPACE, {
rootUri
})

expect(mockShowWarningMessage).to.be.calledOnce
expect(mockCheckout).not.to.be.called
expect(mockGitReset).not.to.be.called
})

it('should reset the workspace if the user confirms they want to', async () => {
const mockCheckout = stub(CliExecutor.prototype, 'checkout').resolves('')
const mockGitReset = stub(ProcessExecution, 'executeProcess').resolves('')

const mockShowWarningMessage = stub(
window,
'showWarningMessage'
).resolves('Discard Changes' as unknown as MessageItem)

await commands.executeCommand(RegisteredCommands.RESET_WORKSPACE, {
rootUri
})

expect(mockShowWarningMessage).to.be.calledOnce
expect(mockCheckout).to.be.calledOnce
expect(mockGitReset).to.be.calledTwice
expect(mockGitReset).to.be.calledWith({
args: ['reset', '--hard', 'HEAD'],
cwd: dvcDemoPath,
executable: 'git'
})
expect(mockGitReset).to.be.calledWith({
args: ['clean', '-f', '-d', '-q'],
cwd: dvcDemoPath,
executable: 'git'
})
})
})
})

0 comments on commit f75f24b

Please sign in to comment.