@@ -10,15 +10,13 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
1010 return importConfig . useBackedupDir ;
1111 }
1212
13+ const sourceDir = importConfig . branchDir || importConfig . contentDir ;
14+
1315 let backupDirPath : string ;
14- const subDir = isSubDirectory ( importConfig ) ;
16+ const subDir = isSubDirectory ( importConfig , sourceDir ) ;
1517
1618 if ( subDir ) {
17- backupDirPath = path . resolve (
18- sanitizePath ( importConfig . contentDir ) ,
19- '..' ,
20- '_backup_' + Math . floor ( Math . random ( ) * 1000 ) ,
21- ) ;
19+ backupDirPath = path . resolve ( sanitizePath ( sourceDir ) , '..' , '_backup_' + Math . floor ( Math . random ( ) * 1000 ) ) ;
2220 if ( importConfig . createBackupDir ) {
2321 cliux . print (
2422 `Warning!!! Provided backup directory path is a sub directory of the content directory, Cannot copy to a sub directory. Hence new backup directory created - ${ backupDirPath } ` ,
@@ -42,7 +40,7 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
4240 if ( backupDirPath ) {
4341 cliux . print ( 'Copying content to the backup directory...' ) ;
4442 return new Promise ( ( resolve , reject ) => {
45- return copy ( importConfig . contentDir , backupDirPath , ( error : any ) => {
43+ return copy ( sourceDir , backupDirPath , ( error : any ) => {
4644 if ( error ) {
4745 trace ( error , 'error' , true ) ;
4846 return reject ( error ) ;
@@ -58,8 +56,8 @@ export default async function backupHandler(importConfig: ImportConfig): Promise
5856 * @param importConfig
5957 * @returns
6058 */
61- function isSubDirectory ( importConfig : ImportConfig ) {
62- const parent = importConfig . contentDir ;
59+ function isSubDirectory ( importConfig : ImportConfig , sourceDir : string ) {
60+ const parent = sourceDir ;
6361 const child = importConfig . createBackupDir ? importConfig . createBackupDir : process . cwd ( ) ;
6462 const relative = path . relative ( parent , child ) ;
6563
0 commit comments