Skip to content

Commit 9e49666

Browse files
committed
fix: added single branch export in the clone command
1 parent 80fc4a0 commit 9e49666

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

packages/contentstack-clone/src/core/util/clone-handler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,8 @@ export class CloneHandler {
644644
importConfig.contentDir = importConfig.data;
645645
}
646646

647-
if (!importConfig.contentDir && importConfig.sourceStackBranch && importConfig.pathDir) {
648-
const dataPath = path.join(importConfig.pathDir, importConfig.sourceStackBranch);
647+
if (!importConfig.contentDir && importConfig.pathDir) {
648+
const dataPath = importConfig.pathDir;
649649
cmd.push('-d', dataPath);
650650
log.debug(`Import data path: ${dataPath}`, this.config.cloneContext);
651651
}
@@ -675,7 +675,7 @@ export class CloneHandler {
675675
cmd: cmd.join(' '),
676676
targetStack: importConfig.apiKey || importConfig.target_stack,
677677
targetBranch: importConfig.targetStackBranch,
678-
dataPath: importConfig.contentDir || (importConfig.pathDir && importConfig.sourceStackBranch ? path.join(importConfig.pathDir, importConfig.sourceStackBranch) : undefined)
678+
dataPath: importConfig.contentDir || importConfig.pathDir || undefined
679679
});
680680
log.debug('Running import command', { ...this.config.cloneContext, cmd });
681681
const importData = importCmd.run(cmd);
@@ -804,9 +804,10 @@ export class CloneHandler {
804804
];
805805
let successMsg: string;
806806
let selectedValue: any = {};
807-
// Resolve path to package root - go up 3 levels from __dirname (core/util -> package root)
807+
// Export root only (single-branch layout: modules live directly under -d, not pathDir/<branch>)
808808
const cloneTypePackageRoot = path.resolve(__dirname, '../../..');
809-
this.config.contentDir = path.join(cloneTypePackageRoot, 'contents', this.config.sourceStackBranch || '');
809+
this.config.contentDir =
810+
this.config.pathDir || path.join(cloneTypePackageRoot, 'contents');
810811
log.debug(`Clone content directory: ${this.config.contentDir}`, this.config.cloneContext);
811812

812813
if (!this.config.cloneType) {

packages/contentstack-clone/src/types/clone-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface CloneConfig {
3131
forceStopMarketplaceAppsPrompt?: boolean;
3232

3333
// Data and modules
34-
/** Path to exported content for import (aligns with import plugin's contentDir) */
34+
/** Export root directory for import (same path as export `-d`; not a branch-named subdirectory) */
3535
contentDir?: string;
3636
modules?: string[];
3737
filteredModules?: string[];

packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('CloneHandler - Commands', () => {
195195
expect(cmdArgs).to.include('dest-alias');
196196
});
197197

198-
it('should execute import command with sourceStackBranch data path (covers lines 637-641)', async () => {
198+
it('should execute import command with pathDir as export root when contentDir unset (single-branch layout)', async () => {
199199
const config: CloneConfig = {
200200
cloneContext: {
201201
command: 'test',
@@ -216,11 +216,10 @@ describe('CloneHandler - Commands', () => {
216216

217217
expect(fsStub.writeFileSync.calledTwice).to.be.true;
218218
expect(importCmdStub.run.calledOnce).to.be.true;
219-
// Verify -d flag with data path is added (line 639)
220219
const cmdArgs = importCmdStub.run.firstCall.args[0];
221220
expect(cmdArgs).to.include('-d');
222221
const dataPathIndex = cmdArgs.indexOf('-d');
223-
expect(cmdArgs[dataPathIndex + 1]).to.include('/test/path/main');
222+
expect(cmdArgs[dataPathIndex + 1]).to.equal('/test/path');
224223
});
225224

226225
it('should execute import command with data path instead of sourceStackBranch (covers line 637 condition)', async () => {

0 commit comments

Comments
 (0)