Skip to content

Commit daecf6c

Browse files
fix: add warning when nothing to delete
1 parent d813973 commit daecf6c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/commands/project/delete/source.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import fs from 'node:fs';
99
import path from 'node:path';
1010
import os from 'node:os';
11-
1211
import { Interfaces } from '@oclif/core';
1312
import { Lifecycle, Messages, Org, SfError } from '@salesforce/core';
1413
import {
@@ -188,7 +187,10 @@ export class Source extends SfCommand<DeleteSourceJson> {
188187
// if we didn't find any components to delete, let the user know and exit
189188
this.styledHeader(tableHeader('Deleted Source'));
190189
this.log('No results found');
191-
return;
190+
if (this.componentSet.forceIgnoredPaths?.size) {
191+
// we have nothing in the CS, and something forceignored, let the user know they're trying to delete a forceignored file
192+
this.warn('Attempting to delete metadata that conflicts with a .forceignore entry');
193+
}
192194
}
193195

194196
// create a new ComponentSet and mark everything for deletion
@@ -285,7 +287,7 @@ export class Source extends SfCommand<DeleteSourceJson> {
285287
*/
286288
protected async resolveSuccess(): Promise<void> {
287289
// if deploy failed restore the stashed files if they exist
288-
if (this.deployResult?.response?.status !== RequestStatus.Succeeded) {
290+
if (this.deployResult && this.deployResult.response?.status !== RequestStatus.Succeeded) {
289291
process.exitCode = 1;
290292
await Promise.all(
291293
this.mixedDeployDelete.delete.map(async (file) => {

test/commands/delete/source.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
SourceComponent,
1616
} from '@salesforce/source-deploy-retrieve';
1717
import { Lifecycle, SfProject } from '@salesforce/core';
18-
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
18+
import { fromStub, spyMethod, stubInterface, stubMethod } from '@salesforce/ts-sinon';
1919
import { Config } from '@oclif/core';
2020
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
2121
import { SfCommand } from '@salesforce/sf-plugins-core';
@@ -205,6 +205,17 @@ describe('project delete source', () => {
205205
expect(rmStub.callCount).to.equal(2);
206206
});
207207

208+
it('should warn if everything is forceignored', async () => {
209+
buildComponentSetStub.restore();
210+
const warnSpy = spyMethod($$.SANDBOX, SfCommand.prototype, 'warn');
211+
buildComponentSetStub = stubMethod($$.SANDBOX, ComponentSetBuilder, 'build').resolves({
212+
forceIgnoredPaths: new Set<string>('myPath'),
213+
toArray: () => [],
214+
});
215+
await runDeleteCmd(['--metadata', 'ApexClass:MyClass', '--json', '-r']);
216+
expect(warnSpy.calledOnce).to.be.true;
217+
});
218+
208219
it('should pass along metadata', async () => {
209220
const metadata = ['ApexClass:MyClass'];
210221
await runDeleteCmd(['--metadata', metadata[0], '--json', '-r']);

0 commit comments

Comments
 (0)