Skip to content

Commit 4cbad4c

Browse files
Vikram KaltaVikram Kalta
authored andcommitted
fix: added missing branch flag handling
1 parent 3615ace commit 4cbad4c

File tree

1 file changed

+21
-0
lines changed
  • packages/contentstack-import/src/commands/cm/stacks

1 file changed

+21
-0
lines changed

packages/contentstack-import/src/commands/cm/stacks/import.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,27 @@ export default class ImportCommand extends Command {
148148
backupDir = importConfig.cliLogsPath || importConfig.backupDir;
149149

150150
const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig);
151+
152+
if (!flags.branch) {
153+
try {
154+
const branches = await managementAPIClient
155+
.stack({ api_key: importConfig.apiKey })
156+
.branch()
157+
.query()
158+
.find()
159+
.then(({ items }: any) => items)
160+
if (branches.length) {
161+
flags.branch = 'main';
162+
}
163+
} catch (error) {
164+
// Branch not enabled, just the let flow continue
165+
log(
166+
importConfig,
167+
`The branch is not enabled for this stack - ${formatError(error)}`,
168+
'error',
169+
);
170+
}
171+
}
151172
const moduleImporter = new ModuleImporter(managementAPIClient, importConfig);
152173
const result = await moduleImporter.start();
153174

0 commit comments

Comments
 (0)