fix(import): align import with single-branch export, import; path resolution and target branch handling#36
Open
fix(import): align import with single-branch export, import; path resolution and target branch handling#36
Conversation
…olution and target branch handling
🔒 Security Scan Results
⏱️ SLA Breach Summary
✅ BUILD PASSED - All security checks passed |
aman19K
approved these changes
Mar 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Single-branch export layout and import path/branch handling
Summary
branches.jsonis written at the export root. Variants export uses the same base path so variant data lives at the export root.branches.jsonto set the target branch. The target branch is determined only by--branch/--branch-aliasor by defaulting from the target stack. Stack client is created withbranch_uidwhenever a target branch is set so all API calls (including variants) use the correct branch.branchDir ?? exportDir). Import uses the main import’scontentDir,backupDir, andbranchName; no path or branch logic in the variants package.Background
<path>/main,<path>/dev).branches.jsonat root lists branch metadata (e.g. the exported branch or all stack branches).branchNamefrombranches.json(source stack), which is wrong when importing into another stack. The target branch must come only from--branch/--branch-aliasor the target stack default.Changes
1. Export (contentstack-export)
branchDiris set toexportDirso there are no per-branch subfolders.branchDir ?? exportDirso all content (stack, entries, assets, etc.) is written at the same root.setup-branches(one or all branches). Used only for metadata; not used by import to choose the target branch.2. Variants export (contentstack-variants)
exportConfig.branchDir ?? exportConfig.exportDir(or equivalent) so variant data is written at the same export root as the rest of the stack.branchDir = exportDir, variant export writes under that root with no branch subfolders.3. Import path resolution (contentstack-import)
branches.jsonor calls branch selection. Resolved path is always the user-provided content directory (export root).contentDir(andbranchDirwhere used) is set from this resolved path.importConfig.branchNameis never set from path resolution. It is set only from--branch/--branch-aliasin config or fromsetupBranchConfig()(target stack, e.g.main).askBranchSelection,readFilein path resolver) removed if applicable.4. Stack client and branch_uid (contentstack-import)
branch_uidonly when bothbranchAliasandbranchNamewere set (e.g. after--branch-alias). Using only--branchor the default branch did not setbranch_uid.branch_uid: this.importConfig.branchNamewheneverbranchNameis set (from--branch,--branch-alias, or default). All import API calls, including variant-entries, use the intended target branch.5. Variants import (contentstack-variants)
ImportConfigfrom the main import (contentDir,backupDir,branchName). It uses:Files touched
cli-plugins/packages/contentstack-export/– single-branch layout, path helpers,branchDirusage,setup-branches/module-exporter(as changed in your branch).cli-plugins/packages/contentstack-variants/src/export/– use ofbranchDir ?? exportDir(or equivalent) for all modules; no new branch subfolders.cli-plugins/packages/contentstack-import/src/utils/import-path-resolver.ts,src/import/module-importer.ts– path resolution, no branch selection, stack clientbranch_uidwhenbranchNameis set.contentDir/backupDir/branchNamefrom main import.(Add or remove specific file paths to match your actual staged changes.)
Testing
--branch. Confirm content andbranches.jsonare at the export root and variant export data is under the same root.--data-dirpointing at that export root, run import with--branch, with--branch-alias, and with neither. Confirm path resolves to the root, no branch prompt frombranches.json, and content is imported into the expected target branch (including variant-entries).