@@ -13,38 +13,46 @@ const mergeHandler = async (options: MergeOptions, logger: Logger) => {
1313 return ;
1414 }
1515
16- const checkedProject = workspace . getActiveProject ( ) ;
17- if ( ! checkedProject ) {
16+ // The target project - the think we apply changes to - is
17+ // whatever is checked out
18+ const targetProject = workspace . getActiveProject ( ) ;
19+ if ( ! targetProject ) {
1820 logger . error ( `No project currently checked out` ) ;
1921 return ;
2022 }
2123
22- const mProject = workspace . get ( options . projectName ) ;
23- if ( ! mProject ) {
24- logger . error (
25- `Project with id/name ${ options . projectName } not found in the workspace`
26- ) ;
24+ // Lookup the source project - the thing we are getting changes from
25+ let sourceProject ;
26+ if ( / \. ( y a m l | j s o n ) $ / . test ( options . projectName ) ) {
27+ const filePath = path . join ( commandPath , options . projectName ) ;
28+ logger . debug ( 'Loading source project from path ' , filePath ) ;
29+ sourceProject = await Project . from ( 'path' , filePath ) ;
30+ } else {
31+ sourceProject = workspace . get ( options . projectName ) ;
32+ }
33+ if ( ! sourceProject ) {
34+ logger . error ( `Project "${ options . projectName } " not found in the workspace` ) ;
2735 return ;
2836 }
2937
30- if ( checkedProject . name === mProject . name ) {
38+ if ( targetProject . name === sourceProject . name ) {
3139 logger . error ( 'Merging into the same project not allowed' ) ;
3240 return ;
3341 }
3442
35- if ( ! checkedProject . name ) {
43+ if ( ! targetProject . name ) {
3644 logger . error ( 'The checked out project has no name/id' ) ;
3745 return ;
3846 }
3947
40- const finalPath = workspace . getProjectPath ( checkedProject . name ) ;
48+ const finalPath = workspace . getProjectPath ( targetProject . name ) ;
4149 if ( ! finalPath ) {
4250 logger . error ( 'Path to checked out project not found.' ) ;
4351 return ;
4452 }
4553
4654 // TODO pick options from the terminal
47- const final = Project . merge ( mProject , checkedProject , {
55+ const final = Project . merge ( sourceProject , targetProject , {
4856 removeUnmapped : options . removeUnmapped ,
4957 workflowMappings : options . workflowMappings ,
5058 } ) ;
@@ -61,7 +69,7 @@ const mergeHandler = async (options: MergeOptions, logger: Logger) => {
6169 logger
6270 ) ;
6371 logger . success (
64- `Project ${ mProject . name } has been merged into Project ${ checkedProject . name } successfully`
72+ `Project ${ sourceProject . name } has been merged into Project ${ targetProject . name } successfully`
6573 ) ;
6674} ;
6775
0 commit comments