Skip to content

Commit

Permalink
Merge pull request #1069 from salesforcecli/wr/purgeOnDelete
Browse files Browse the repository at this point in the history
fix: allow purge-on-delete with mdapi dirs
  • Loading branch information
shetzel authored Jun 27, 2024
2 parents 4e2b8bb + f4d1c63 commit 98b8557
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
8 changes: 8 additions & 0 deletions messages/deploy.metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ To deploy multiple metadata components, either set multiple --metadata <name> fl

<%= config.bin %> <%= command.id %> --metadata ApexClass --test-level RunLocalTests

- Deploy all metadata formatted files in the "MDAPI" directory:

<%= config.bin %> <%= command.id %> --metadata-dir MDAPI

- Deploy all metadata formatted files in the "MDAPI" directory; items listed in the MDAPI/destructiveChangesPre.xml and MDAPI/destructiveChangesPost.xml manifests are immediately eligible for deletion rather than stored in the Recycle Bin:

<%= config.bin %> <%= command.id %> --metadata-dir MDAPI --purge-on-delete

# flags.pre-destructive-changes.summary

File path for a manifest (destructiveChangesPre.xml) of components to delete before the deploy.
Expand Down
5 changes: 3 additions & 2 deletions src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
}),
'purge-on-delete': Flags.boolean({
summary: messages.getMessage('flags.purge-on-delete.summary'),
dependsOn: ['manifest'],
relationships: [{ type: 'some', flags: ['pre-destructive-changes', 'post-destructive-changes'] }],
relationships: [
{ type: 'some', flags: ['pre-destructive-changes', 'manifest', 'metadata-dir', 'post-destructive-changes'] },
],
helpGroup: destructiveFlags,
}),
'pre-destructive-changes': Flags.file({
Expand Down
35 changes: 34 additions & 1 deletion test/nuts/destructive/destructiveChanges.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

import * as path from 'node:path';
import { writeFileSync } from 'node:fs';
import { copyFileSync, writeFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';
import { assert, expect } from 'chai';
import { execCmd } from '@salesforce/cli-plugins-testkit';
import { SourceTestkit } from '@salesforce/source-testkit';
Expand Down Expand Up @@ -230,6 +231,38 @@ describe('project deploy start --destructive NUTs', () => {
expect(preDeleted).to.be.true;
expect(postDeleted).to.be.true;
});

it('should delete a class in metadata api format with --purge-on-delete', async () => {
const pre = createApexClass('pre').apexName;
const post = createApexClass('post').apexName;
let preDeleted = await isNameObsolete(testkit.username, 'ApexClass', pre);
let postDeleted = await isNameObsolete(testkit.username, 'ApexClass', post);

expect(preDeleted).to.be.false;
expect(postDeleted).to.be.false;
// convert file to deploy to MDAPI format
execCmd('project:convert:source --output-dir mdapi --metadata ApexClass:GeocodingService');

createManifest(`ApexClass:${post}`, 'post');
createManifest(`ApexClass:${pre}`, 'pre');
// move the destructive changes files into the mdapi dirt
copyFileSync(
join(testkit.projectDir, 'destructiveChangesPre.xml'),
join(testkit.projectDir, 'mdapi', 'destructiveChangesPre.xml')
);
copyFileSync(
join(testkit.projectDir, 'destructiveChangesPost.xml'),
join(testkit.projectDir, 'mdapi', 'destructiveChangesPost.xml')
);
execCmd('project:deploy:start --json --metadata-dir mdapi --purge-on-delete', {
ensureExitCode: 0,
});

preDeleted = await isNameObsolete(testkit.username, 'ApexClass', pre);
postDeleted = await isNameObsolete(testkit.username, 'ApexClass', post);
expect(preDeleted).to.be.true;
expect(postDeleted).to.be.true;
});
});

describe('errors', () => {
Expand Down

0 comments on commit 98b8557

Please sign in to comment.