@@ -3,6 +3,7 @@ import { $TSContext, AmplifyError } from '@aws-amplify/amplify-cli-core';
33import { printer } from '@aws-amplify/amplify-prompts' ;
44import { DescribeChangeSetOutput } from '@aws-sdk/client-cloudformation' ;
55import { STATEFUL_RESOURCES } from './stateful-resources' ;
6+ import execa from 'execa' ;
67
78export class AmplifyGen2MigrationValidations {
89 constructor ( private readonly context : $TSContext ) { }
@@ -12,7 +13,28 @@ export class AmplifyGen2MigrationValidations {
1213 }
1314
1415 public async validateWorkingDirectory ( ) : Promise < void > {
15- printer . warn ( 'Not implemented' ) ;
16+ const { stdout : statusOutput } = await execa ( 'git' , [ 'status' , '--porcelain' ] ) ;
17+ if ( statusOutput . trim ( ) ) {
18+ throw new AmplifyError ( 'MigrationError' , {
19+ message : 'Working directory has uncommitted changes' ,
20+ resolution : 'Commit or stash your changes before proceeding with migration.' ,
21+ } ) ;
22+ }
23+
24+ try {
25+ const { stdout : unpushedOutput } = await execa ( 'git' , [ 'log' , '@{u}..' , '--oneline' ] ) ;
26+ if ( unpushedOutput . trim ( ) ) {
27+ throw new AmplifyError ( 'MigrationError' , {
28+ message : 'Local branch has unpushed commits' ,
29+ resolution : 'Push your commits before proceeding with migration.' ,
30+ } ) ;
31+ }
32+ } catch ( err : any ) {
33+ if ( err instanceof AmplifyError ) throw err ;
34+ if ( ! err . message ?. includes ( 'no upstream' ) && ! err . stderr ?. includes ( 'no upstream' ) ) {
35+ throw err ;
36+ }
37+ }
1638 }
1739
1840 public async validateDeploymentStatus ( ) : Promise < void > {
0 commit comments