Skip to content

Commit 938ae14

Browse files
committed
fix: include --output-dir only when output_dir is provided
PR #3901 added the `--output-dir` option to the `retrieve_components` task. When `output_dir` was `None`, it used the target (e.g. `force-app`) as the value. The Salesforce CLI rejects using a package directory as the output directory, so this caused an error reported in #3918. This commit builds the sfdx args without `--output-dir` by default. It appends `--output-dir <path>` only when `output_dir` is not `None`. This lets the CLI select the default output dir when output_dir is not given. When output_dir is not set, files go to the package directory from the manifest, as the CLI expects.
1 parent 59785ab commit 938ae14

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

cumulusci/tasks/salesforce/sourcetracking.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def _reset_sfdx_snapshot(self):
182182
retrieve_changes_task_options["output_dir"] = {
183183
"description": (
184184
"The output directory for the retrieved metadata. "
185-
+ "If not specified, defaults to force-app or the target directory passed to retrieve changes."
185+
+ "If set, this will be passed as the --output-dir option to 'sfdx project retrieve start'. "
186+
+ "If not set, the default output directory will be used by Salesforce CLI (usually 'force-app')."
186187
),
187188
"required": False,
188189
}
@@ -247,10 +248,8 @@ def retrieve_components(
247248
to a namespace prefix to replace it with a `%%%NAMESPACE%%%` token.
248249
"""
249250

250-
# Always use output_dir if specified, else use target
251-
retrieve_target = (
252-
os.path.realpath(output_dir) if output_dir else os.path.realpath(target)
253-
)
251+
# Resolve output_dir if provided; otherwise let sfdx choose defaults
252+
retrieve_target = os.path.realpath(output_dir) if output_dir else None
254253
profiles = []
255254
# If retrieve_complete_profile and project_config is None, raise error
256255
# This is because project_config is only required if retrieve_complete_profile is True
@@ -302,21 +301,23 @@ def retrieve_components(
302301
_write_manifest(components, package_xml_path, api_version)
303302

304303
# Retrieve specified components in DX format
304+
args = [
305+
"-a",
306+
str(api_version),
307+
"-x",
308+
os.path.join(package_xml_path, "package.xml"),
309+
"-w",
310+
"5",
311+
"--ignore-conflicts",
312+
]
313+
if retrieve_target is not None:
314+
args.extend(["--output-dir", retrieve_target])
315+
305316
p = sfdx(
306317
"project retrieve start",
307318
access_token=org_config.access_token,
308319
log_note="Retrieving components",
309-
args=[
310-
"-a",
311-
str(api_version),
312-
"-x",
313-
os.path.join(package_xml_path, "package.xml"),
314-
"-w",
315-
"5",
316-
"--ignore-conflicts",
317-
"--output-dir",
318-
retrieve_target,
319-
],
320+
args=args,
320321
capture_output=capture_output,
321322
check_return=True,
322323
env={"SF_ORG_INSTANCE_URL": org_config.instance_url},

0 commit comments

Comments
 (0)