Skip to content

Commit 1587393

Browse files
authored
Merge pull request #1262 from salesforcecli/wr/sourceDeleteUndefined
fix: add warning when nothing to delete
2 parents d813973 + f0ae41f commit 1587393

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/commands/project/delete/source.ts

+7-3
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,12 @@ 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+
const ignoredComponentPaths = Array.from(this.componentSet.forceIgnoredPaths).toString();
193+
this.warn(`Attempting to delete metadata that conflicts with a .forceignore entry: ${ignoredComponentPaths}
194+
Update the .forceignore file and try again.`);
195+
}
192196
}
193197

194198
// create a new ComponentSet and mark everything for deletion
@@ -285,7 +289,7 @@ export class Source extends SfCommand<DeleteSourceJson> {
285289
*/
286290
protected async resolveSuccess(): Promise<void> {
287291
// if deploy failed restore the stashed files if they exist
288-
if (this.deployResult?.response?.status !== RequestStatus.Succeeded) {
292+
if (this.deployResult && this.deployResult.response?.status !== RequestStatus.Succeeded) {
289293
process.exitCode = 1;
290294
await Promise.all(
291295
this.mixedDeployDelete.delete.map(async (file) => {

test/commands/delete/source.test.ts

+12-1
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)