-
Notifications
You must be signed in to change notification settings - Fork 29
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
Reduce steps needed to reset workspace #860
Changes from all commits
e52d9e4
9c5ee7d
489354d
ce701f7
40b9cfd
fe4b14e
f75f24b
d60e25a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,18 @@ export const getAllUntracked = async ( | |
]) | ||
return new Set([...files, ...dirs]) | ||
} | ||
|
||
export const gitResetWorkspace = async ( | ||
repositoryRoot: string | ||
): Promise<void> => { | ||
await executeProcess({ | ||
args: ['reset', '--hard', 'HEAD'], | ||
cwd: repositoryRoot, | ||
executable: 'git' | ||
}) | ||
await executeProcess({ | ||
args: ['clean', '-f', '-d', '-q'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] We need this to remove untracked from the workspace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this mirrors what the git extension does |
||
cwd: repositoryRoot, | ||
executable: 'git' | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { relative } from 'path' | ||
import { Uri } from 'vscode' | ||
import { tryThenMaybeForce } from '../../cli/actions' | ||
import { CommandId, InternalCommands } from '../../commands/internal' | ||
import { Flag } from '../../cli/args' | ||
import { | ||
AvailableCommands, | ||
CommandId, | ||
InternalCommands | ||
} from '../../commands/internal' | ||
import { gitResetWorkspace } from '../../git' | ||
import { getWarningResponse } from '../../vscode/modal' | ||
|
||
export type Resource = { | ||
dvcRoot: string | ||
|
@@ -40,3 +47,28 @@ export const getRootCommand = | |
|
||
return tryThenMaybeForce(internalCommands, commandId, cwd) | ||
} | ||
|
||
export const getResetRootCommand = | ||
(internalCommands: InternalCommands): RootCommand => | ||
async ({ rootUri }) => { | ||
const cwd = rootUri.fsPath | ||
|
||
const response = await getWarningResponse( | ||
'Are you sure you want to discard ALL workspace changes?\n' + | ||
'This is IRREVERSIBLE!\n' + | ||
'Your current working set will be FOREVER LOST if you proceed.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] This pretty much matches what the git extension throws up. You can see a comparison in the first demo. |
||
'Discard Changes' | ||
) | ||
|
||
if (response !== 'Discard Changes') { | ||
return | ||
} | ||
|
||
await gitResetWorkspace(cwd) | ||
|
||
return internalCommands.executeCommand( | ||
AvailableCommands.CHECKOUT, | ||
cwd, | ||
Flag.FORCE | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,11 @@ import { window, commands, Uri, MessageItem } from 'vscode' | |
import { Disposable } from '../../../extension' | ||
import { CliExecutor } from '../../../cli/executor' | ||
import { dvcDemoPath } from '../util' | ||
import { RegisteredCliCommands } from '../../../commands/external' | ||
import { | ||
RegisteredCliCommands, | ||
RegisteredCommands | ||
} from '../../../commands/external' | ||
import * as ProcessExecution from '../../../processExecution' | ||
|
||
suite('Source Control Management Test Suite', () => { | ||
const disposable = Disposable.fn() | ||
|
@@ -179,5 +183,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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] Definitely do not want to be calling these actions in tests |
||
}) | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[F] This now goes into a new context menu which we can build on.