Skip to content

Commit 62bab11

Browse files
authored
Revert "Improve reset the workspace SCM command (#1900)" (#1910)
This reverts commit 4739b79.
1 parent 39934c2 commit 62bab11

File tree

12 files changed

+34
-89
lines changed

12 files changed

+34
-89
lines changed

extension/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@
166166
"category": "DVC",
167167
"icon": "$(trash)"
168168
},
169-
{
170-
"title": "%command.discardWorkspaceChanges%",
171-
"command": "dvc.discardWorkspaceChanges",
172-
"category": "DVC",
173-
"icon": "$(discard)"
174-
},
175169
{
176170
"title": "%command.experimentGarbageCollect%",
177171
"command": "dvc.experimentGarbageCollect",
@@ -311,6 +305,12 @@
311305
"command": "dvc.renameTarget",
312306
"category": "DVC"
313307
},
308+
{
309+
"title": "%command.resetWorkspace%",
310+
"command": "dvc.resetWorkspace",
311+
"category": "DVC",
312+
"icon": "$(discard)"
313+
},
314314
{
315315
"title": "%command.runExperiment%",
316316
"command": "dvc.runExperiment",
@@ -682,7 +682,7 @@
682682
"when": "false"
683683
},
684684
{
685-
"command": "dvc.discardWorkspaceChanges",
685+
"command": "dvc.resetWorkspace",
686686
"when": "dvc.commands.available && dvc.project.available"
687687
},
688688
{
@@ -792,7 +792,7 @@
792792
],
793793
"scm/title": [
794794
{
795-
"command": "dvc.discardWorkspaceChanges",
795+
"command": "dvc.resetWorkspace",
796796
"group": "navigation@1",
797797
"when": "scmProvider == dvc && dvc.commands.available"
798798
},

extension/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"command.copyFilePath": "Copy Path",
1616
"command.copyRelativeFilePath": "Copy Relative Path",
1717
"command.deleteTarget": "Delete",
18-
"command.discardWorkspaceChanges": "Discard Workspace Changes",
1918
"command.experimentGarbageCollect": "Garbage Collect Experiments",
2019
"command.findInFolder": "Find in Folder...",
2120
"command.getStarted": "Get Started",
@@ -40,6 +39,7 @@
4039
"command.removeQueuedExperiment": "Remove Queued Experiment",
4140
"command.removeTarget": "Remove",
4241
"command.renameTarget": "Rename",
42+
"command.resetWorkspace": "Reset the Workspace",
4343
"command.runExperiment": "Run Experiment",
4444
"command.resumeCheckpointExperiment": "Resume Experiment",
4545
"command.startExperimentsQueue": "Start the Experiments Queue",

extension/src/commands/external.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export enum RegisteredCommands {
6868
DELETE_TARGET = 'dvc.deleteTarget',
6969
MOVE_TARGETS = 'dvc.moveTargets',
7070

71-
DISCARD_WORKSPACE_CHANGES = 'dvc.discardWorkspaceChanges',
71+
RESET_WORKSPACE = 'dvc.resetWorkspace',
7272

7373
TRACKED_EXPLORER_OPEN_FILE = 'dvc.views.trackedExplorerTree.openFile',
7474
TRACKED_EXPLORER_COMPARE_SELECTED = 'dvc.compareSelected',

extension/src/git.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ export const getAllUntracked = async (
5151
return new Set([...files, ...dirs])
5252
}
5353

54-
export const getHasChanges = async (
55-
repositoryRoot: string
56-
): Promise<boolean> => {
57-
const output = await executeProcess({
58-
args: ['status', '-z', '-uall'],
59-
cwd: repositoryRoot,
60-
executable: 'git'
61-
})
62-
return !!output
63-
}
64-
6554
export const gitReset = (cwd: string, ...args: string[]): Promise<string> =>
6655
executeProcess({
6756
args: ['reset', ...args],

extension/src/repository/commands/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const registerRootCommands = (
7373
)
7474

7575
internalCommands.registerExternalCommand<Root>(
76-
RegisteredCommands.DISCARD_WORKSPACE_CHANGES,
76+
RegisteredCommands.RESET_WORKSPACE,
7777
getResetRootCommand(repositories, internalCommands)
7878
)
7979
}

extension/src/repository/data/index.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import { Event, EventEmitter, RelativePattern } from 'vscode'
33
import { AvailableCommands, InternalCommands } from '../../commands/internal'
44
import { DiffOutput, ListOutput, StatusOutput } from '../../cli/reader'
55
import { isAnyDvcYaml } from '../../fileSystem'
6-
import {
7-
DOT_GIT,
8-
getAllUntracked,
9-
getGitRepositoryRoot,
10-
getHasChanges
11-
} from '../../git'
6+
import { DOT_GIT, getAllUntracked, getGitRepositoryRoot } from '../../git'
127
import { ProcessManager } from '../../processManager'
138
import {
149
createFileSystemWatcher,
@@ -25,7 +20,6 @@ export type Data = {
2520
diffFromHead: DiffOutput
2621
diffFromCache: StatusOutput
2722
untracked: Set<string>
28-
hasGitChanges: boolean
2923
tracked?: ListOutput[]
3024
}
3125

@@ -103,31 +97,25 @@ export class RepositoryData extends DeferredDisposable {
10397
this.dvcRoot
10498
)
10599

106-
const [diffFromHead, diffFromCache, untracked, hasGitChanges] =
100+
const [diffFromHead, diffFromCache, untracked] =
107101
await this.getPartialUpdateData()
108102

109103
return this.notifyChanged({
110104
diffFromCache,
111105
diffFromHead,
112-
hasGitChanges,
113106
tracked,
114107
untracked
115108
})
116109
}
117110

118111
private async partialUpdate() {
119-
const [diffFromHead, diffFromCache, untracked, hasGitChanges] =
112+
const [diffFromHead, diffFromCache, untracked] =
120113
await this.getPartialUpdateData()
121-
return this.notifyChanged({
122-
diffFromCache,
123-
diffFromHead,
124-
hasGitChanges,
125-
untracked
126-
})
114+
return this.notifyChanged({ diffFromCache, diffFromHead, untracked })
127115
}
128116

129117
private async getPartialUpdateData(): Promise<
130-
[DiffOutput, StatusOutput, Set<string>, boolean]
118+
[DiffOutput, StatusOutput, Set<string>]
131119
> {
132120
const diffFromCache =
133121
await this.internalCommands.executeCommand<StatusOutput>(
@@ -140,12 +128,9 @@ export class RepositoryData extends DeferredDisposable {
140128
this.dvcRoot
141129
)
142130

143-
const [untracked, hasGitChanges] = await Promise.all([
144-
getAllUntracked(this.dvcRoot),
145-
getHasChanges(this.dvcRoot)
146-
])
131+
const untracked = await getAllUntracked(this.dvcRoot)
147132

148-
return [diffFromHead, diffFromCache, untracked, hasGitChanges]
133+
return [diffFromHead, diffFromCache, untracked]
149134
}
150135

151136
private notifyChanged(data: Data) {

extension/src/repository/model/index.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ describe('RepositoryState', () => {
7676
model.setState({
7777
diffFromCache: status,
7878
diffFromHead: diff,
79-
hasGitChanges: true,
8079
tracked: list,
8180
untracked: new Set<string>()
8281
})
@@ -85,7 +84,6 @@ describe('RepositoryState', () => {
8584
added: emptySet,
8685
deleted: new Set([join(dvcDemoPath, deleted)]),
8786
gitModified: new Set([join(dvcDemoPath, output)]),
88-
hasGitChanges: true,
8987
hasRemote: new Set(list.map(entry => join(dvcDemoPath, entry.path))),
9088
modified: new Set([
9189
join(dvcDemoPath, rawDataDir),
@@ -124,7 +122,6 @@ describe('RepositoryState', () => {
124122
model.setState({
125123
diffFromCache: status,
126124
diffFromHead: diff,
127-
hasGitChanges: true,
128125
tracked: list,
129126
untracked: new Set<string>()
130127
})
@@ -136,7 +133,6 @@ describe('RepositoryState', () => {
136133
join(dvcDemoPath, rawDataDir),
137134
join(dvcDemoPath, data)
138135
]),
139-
hasGitChanges: true,
140136
hasRemote: new Set([join(dvcDemoPath, data)]),
141137
modified: emptySet,
142138
notInCache: emptySet,
@@ -169,7 +165,6 @@ describe('RepositoryState', () => {
169165
model.setState({
170166
diffFromCache: status,
171167
diffFromHead: diff,
172-
hasGitChanges: true,
173168
tracked: list,
174169
untracked: new Set<string>()
175170
})
@@ -178,7 +173,6 @@ describe('RepositoryState', () => {
178173
added: emptySet,
179174
deleted: emptySet,
180175
gitModified: emptySet,
181-
hasGitChanges: true,
182176
hasRemote: new Set([join(dvcDemoPath, data)]),
183177
modified: new Set([join(dvcDemoPath, rawDataDir)]),
184178
notInCache: emptySet,
@@ -208,15 +202,13 @@ describe('RepositoryState', () => {
208202
model.setState({
209203
diffFromCache: status,
210204
diffFromHead: diff,
211-
hasGitChanges: false,
212205
untracked: new Set<string>()
213206
})
214207

215208
expect(model.getState()).toStrictEqual({
216209
added: emptySet,
217210
deleted: emptySet,
218211
gitModified: emptySet,
219-
hasGitChanges: false,
220212
hasRemote: emptySet,
221213
modified: emptySet,
222214
notInCache: emptySet,
@@ -359,7 +351,6 @@ describe('RepositoryState', () => {
359351
model.setState({
360352
diffFromCache: status,
361353
diffFromHead: diff,
362-
hasGitChanges: true,
363354
tracked: list,
364355
untracked: new Set<string>()
365356
})
@@ -377,7 +368,6 @@ describe('RepositoryState', () => {
377368
added: emptySet,
378369
deleted: emptySet,
379370
gitModified: emptySet,
380-
hasGitChanges: true,
381371
hasRemote: new Set([
382372
...list.map(({ path }) => resolve(dvcDemoPath, path)),
383373
resolve(dvcDemoPath, 'data', 'MNIST', 'raw')
@@ -551,7 +541,6 @@ describe('RepositoryState', () => {
551541
model.setState({
552542
diffFromCache: status,
553543
diffFromHead: diff,
554-
hasGitChanges: true,
555544
tracked: list,
556545
untracked: new Set<string>()
557546
})
@@ -569,7 +558,6 @@ describe('RepositoryState', () => {
569558
added: emptySet,
570559
deleted: emptySet,
571560
gitModified: emptySet,
572-
hasGitChanges: true,
573561
hasRemote: new Set([
574562
resolve(dvcDemoPath, 'misclassified.jpg'),
575563
resolve(dvcDemoPath, 'model.pt'),

extension/src/repository/model/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ import {
2424
} from '../../cli/reader'
2525
import { Disposable } from '../../class/dispose'
2626
import { sameContents } from '../../util/array'
27-
import { Data } from '../data'
27+
28+
type OutputData = {
29+
diffFromCache: StatusOutput
30+
diffFromHead: DiffOutput
31+
tracked?: ListOutput[]
32+
untracked: Set<string>
33+
}
2834

2935
type ModifiedAndNotInCache = {
3036
[Status.MODIFIED]: Set<string>
@@ -41,7 +47,6 @@ export class RepositoryModel
4147
added: new Set<string>(),
4248
deleted: new Set<string>(),
4349
gitModified: new Set<string>(),
44-
hasGitChanges: false,
4550
modified: new Set<string>(),
4651
notInCache: new Set<string>(),
4752
renamed: new Set<string>(),
@@ -79,17 +84,15 @@ export class RepositoryModel
7984
public setState({
8085
diffFromCache,
8186
diffFromHead,
82-
hasGitChanges,
8387
tracked,
8488
untracked
85-
}: Data) {
89+
}: OutputData) {
8690
if (tracked) {
8791
this.updateTracked(tracked)
8892
}
8993
this.updateStatus(diffFromHead, diffFromCache)
9094

9195
this.state.untracked = untracked
92-
this.state.hasGitChanges = hasGitChanges
9396
}
9497

9598
public hasChanges(): boolean {
@@ -98,8 +101,7 @@ export class RepositoryModel
98101
this.state.deleted.size > 0 ||
99102
this.state.gitModified.size > 0 ||
100103
this.state.modified.size > 0 ||
101-
this.state.renamed.size > 0 ||
102-
this.state.hasGitChanges
104+
this.state.renamed.size > 0
103105
)
104106
}
105107

extension/src/telemetry/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ export interface IEventNamePropertyMapping {
154154
[EventName.COMMIT_TARGET]: undefined
155155
[EventName.COMMIT]: undefined
156156
[EventName.DELETE_TARGET]: undefined
157-
[EventName.DISCARD_WORKSPACE_CHANGES]: undefined
158157
[EventName.INIT]: undefined
159158
[EventName.MOVE_TARGETS]: undefined
160159
[EventName.PULL_TARGET]: undefined
@@ -163,6 +162,7 @@ export interface IEventNamePropertyMapping {
163162
[EventName.PUSH]: undefined
164163
[EventName.REMOVE_TARGET]: undefined
165164
[EventName.RENAME_TARGET]: undefined
165+
[EventName.RESET_WORKSPACE]: undefined
166166

167167
[EventName.GIT_STAGE_ALL]: undefined
168168
[EventName.GIT_UNSTAGE_ALL]: undefined

0 commit comments

Comments
 (0)