Skip to content

Commit dcbded5

Browse files
authored
Force commit action by default (#3726)
1 parent 3ee3023 commit dcbded5

File tree

5 files changed

+8
-80
lines changed

5 files changed

+8
-80
lines changed

extension/src/cli/dvc/executor.test.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -199,30 +199,14 @@ describe('CliExecutor', () => {
199199
})
200200

201201
describe('commit', () => {
202-
it('should call createProcess with the correct parameters to commit a repository', async () => {
202+
it('should call createProcess with the correct parameters to force commit a repository (by default)', async () => {
203203
const cwd = __dirname
204204
const stdout = updatingLockFile
205205
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))
206206

207207
const output = await dvcExecutor.commit(cwd)
208208
expect(output).toStrictEqual(stdout)
209209

210-
expect(mockedCreateProcess).toHaveBeenCalledWith({
211-
args: ['commit'],
212-
cwd,
213-
env: mockedEnv,
214-
executable: 'dvc'
215-
})
216-
})
217-
218-
it('should call createProcess with the correct parameters to force commit a repository', async () => {
219-
const cwd = __dirname
220-
const stdout = updatingLockFile
221-
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))
222-
223-
const output = await dvcExecutor.commit(cwd, Flag.FORCE)
224-
expect(output).toStrictEqual(stdout)
225-
226210
expect(mockedCreateProcess).toHaveBeenCalledWith({
227211
args: ['commit', '-f'],
228212
cwd,
@@ -231,7 +215,7 @@ describe('CliExecutor', () => {
231215
})
232216
})
233217

234-
it('should call createProcess with the correct parameters to commit a target', async () => {
218+
it('should call createProcess with the correct parameters to commit a target (force by default)', async () => {
235219
const cwd = __dirname
236220
const relPath = join(
237221
'data',
@@ -245,28 +229,6 @@ describe('CliExecutor', () => {
245229
const output = await dvcExecutor.commit(cwd, relPath)
246230
expect(output).toStrictEqual(stdout)
247231

248-
expect(mockedCreateProcess).toHaveBeenCalledWith({
249-
args: ['commit', relPath],
250-
cwd,
251-
env: mockedEnv,
252-
executable: 'dvc'
253-
})
254-
})
255-
256-
it('should call createProcess with the correct parameters to force commit a target', async () => {
257-
const cwd = __dirname
258-
const relPath = join(
259-
'data',
260-
'fashion-mnist',
261-
'raw',
262-
't10k-images-idx3-ubyte.gz'
263-
)
264-
const stdout = updatingLockFile
265-
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(stdout))
266-
267-
const output = await dvcExecutor.commit(cwd, relPath, Flag.FORCE)
268-
expect(output).toStrictEqual(stdout)
269-
270232
expect(mockedCreateProcess).toHaveBeenCalledWith({
271233
args: ['commit', relPath, '-f'],
272234
cwd,

extension/src/cli/dvc/executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class DvcExecutor extends DvcCli {
6868
}
6969

7070
public commit(cwd: string, ...args: Args) {
71-
return this.blockAndExecuteProcess(cwd, Command.COMMIT, ...args)
71+
return this.blockAndExecuteProcess(cwd, Command.COMMIT, ...args, Flag.FORCE)
7272
}
7373

7474
public experimentApply(cwd: string, experimentName: string) {

extension/src/repository/commands/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ export const getCommitRootCommand =
115115
return
116116
}
117117

118-
await tryThenMaybeForce(
119-
internalCommands,
118+
await internalCommands.executeCommand(
120119
AvailableCommands.COMMIT,
121120
cwd as string
122121
)

extension/src/repository/commands/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const registerResourceCommands = (internalCommands: InternalCommands): void => {
2929

3030
internalCommands.registerExternalCliCommand<Resource>(
3131
RegisteredCliCommands.COMMIT_TARGET,
32-
getResourceCommand(internalCommands, AvailableCommands.COMMIT)
32+
getSimpleResourceCommand(internalCommands, AvailableCommands.COMMIT)
3333
)
3434
}
3535

extension/src/test/suite/repository/sourceControlManagement/index.test.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,20 @@ suite('Source Control Management Test Suite', () => {
120120
expect(executeCommandSpy).to.be.calledWith('workbench.scm.focus')
121121
})
122122

123-
it('should prompt to force if dvc.commit fails', async () => {
123+
it('should not prompt to force if dvc.commit fails', async () => {
124124
const mockCommit = stub(DvcExecutor.prototype, 'commit')
125125
.onFirstCall()
126126
.rejects({
127127
stderr: 'Use `-f` to force.'
128128
})
129-
.onSecondCall()
130-
.resolves('')
131-
const mockShowWarningMessage = stub(
132-
window,
133-
'showWarningMessage'
134-
).resolves('Force' as unknown as MessageItem)
135-
136129
stubPrivatePrototypeMethod(WorkspaceRepositories, 'hasChanges').returns(
137130
true
138131
)
139132

140133
await commands.executeCommand(RegisteredCliCommands.COMMIT, { rootUri })
141134

142-
expect(mockCommit).to.be.calledTwice
143-
expect(mockShowWarningMessage).to.be.calledOnce
144-
expect(mockCommit).to.be.calledWith(dvcDemoPath)
145-
expect(mockCommit).to.be.calledWith(dvcDemoPath, '-f')
135+
expect(mockCommit).to.be.calledOnce
136+
expect(mockCommit).to.be.calledWithExactly(dvcDemoPath)
146137
})
147138

148139
it('should be able to run dvc.commitTarget without error', async () => {
@@ -156,30 +147,6 @@ suite('Source Control Management Test Suite', () => {
156147
expect(mockCommit).to.be.calledOnce
157148
})
158149

159-
it('should prompt to force if dvc.commitTarget fails', async () => {
160-
const mockCommit = stub(DvcExecutor.prototype, 'commit')
161-
.onFirstCall()
162-
.rejects({
163-
stderr: 'Use `-f` to force.'
164-
})
165-
.onSecondCall()
166-
.resolves('')
167-
const mockShowWarningMessage = stub(
168-
window,
169-
'showWarningMessage'
170-
).resolves('Force' as unknown as MessageItem)
171-
172-
await commands.executeCommand(RegisteredCliCommands.COMMIT_TARGET, {
173-
dvcRoot: dvcDemoPath,
174-
resourceUri
175-
})
176-
177-
expect(mockCommit).to.be.calledTwice
178-
expect(mockShowWarningMessage).to.be.calledOnce
179-
expect(mockCommit).to.be.calledWith(dvcDemoPath, relPath)
180-
expect(mockCommit).to.be.calledWith(dvcDemoPath, relPath, '-f')
181-
})
182-
183150
it('should not prompt to force if dvc.pull fails without a prompt error', async () => {
184151
const mockPull = stub(DvcExecutor.prototype, 'pull')
185152
.onFirstCall()

0 commit comments

Comments
 (0)