Skip to content

Commit f3aeb1b

Browse files
author
Sai Ray
committed
chore: implement validateWorkingDirectory for gen2 migration
1 parent bd1fc47 commit f3aeb1b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/amplify-cli/src/commands/gen2-migration/_validations.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { $TSContext, AmplifyError } from '@aws-amplify/amplify-cli-core';
33
import { printer } from '@aws-amplify/amplify-prompts';
44
import { DescribeChangeSetOutput } from '@aws-sdk/client-cloudformation';
55
import { STATEFUL_RESOURCES } from './stateful-resources';
6+
import execa from 'execa';
67

78
export 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

Comments
 (0)