Skip to content

Commit

Permalink
Merge pull request #1236 from salesforcecli/sh/fix-enoent-on-retrieve
Browse files Browse the repository at this point in the history
fix: no ENOENT when nothing retrieved to specific directory
  • Loading branch information
WillieRuemmele authored Dec 6, 2024
2 parents a2766a2 + 62e9cfa commit 73b79a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
);
return directories;
}
// If we retrieved only a package.xml, just return.
if (this.retrieveResult.getFileResponses().length < 2) {
return;
}

// getFileResponses fails once the files have been moved, calculate where they're moved to, and then move them
this.retrieveResult.getFileResponses().forEach((fileResponse) => {
fileResponse.filePath = fileResponse.filePath?.replace(join('main', 'default'), '');
Expand Down
14 changes: 14 additions & 0 deletions test/nuts/retrieve/metadata.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ describe('retrieve metadata NUTs', () => {
await testkit.expect.filesToBeRetrieved(['myOutput/classes/*', 'myOutput/aura/**/*']);
});

it('should warn when nothing retrieved into output-dir and not throw ENOENT', async () => {
const result = await testkit.retrieve({ args: '--metadata ApexClass:NonExistant --output-dir myOutput' });
expect(result?.status).to.equal(0);
const retrieveResult = result?.result as unknown as RetrieveResultJson;
expect(retrieveResult.success).to.equal(true);
expect(retrieveResult.fileProperties).to.be.an('array').with.lengthOf(1);
expect(retrieveResult.messages).to.deep.equal([
{
fileName: 'unpackaged/package.xml',
problem: "Entity of type 'ApexClass' named 'NonExistant' cannot be found",
},
]);
});

it('should retrieve ApexClasses from wildcard match', async () => {
const response = await testkit.retrieve({ args: '--metadata "ApexClass:Test*"' });
expect(response?.status).to.equal(0);
Expand Down

0 comments on commit 73b79a4

Please sign in to comment.