Skip to content

Commit

Permalink
WIP: test switching to simple-git
Browse files Browse the repository at this point in the history
  • Loading branch information
graygilmore committed Apr 8, 2024
1 parent 8c4ccc7 commit 2b0188e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
44 changes: 33 additions & 11 deletions packages/cli/src/commands/hydrogen/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Flags} from '@oclif/core';
import Command from '@shopify/cli-kit/node/base-command';
import colors from '@shopify/cli-kit/node/colors';
import git, {type FileStatusResult} from 'simple-git';
import {
outputContent,
outputInfo,
Expand Down Expand Up @@ -48,6 +49,7 @@ import {runViteBuild} from './build-vite.js';
import {getViteConfig} from '../../lib/vite-config.js';
import {prepareDiffDirectory} from '../../lib/template-diff.js';
import {hasRemixConfigFile} from '../../lib/remix-config.js';
import {packageManagers} from '../../lib/package-managers.js';

const DEPLOY_OUTPUT_FILE_HANDLE = 'h2_deploy_log.json';

Expand Down Expand Up @@ -252,19 +254,39 @@ export async function runDeploy(
}

if (!forceOnUncommitedChanges && !isCleanGit) {
const {stdout} = await execAsync(`git status -s`);

throw new AbortError(
`Uncommitted changes detected:\n\n${stdout}`.trimEnd(),
null,
let errorMessage = 'Uncommitted changes detected';
const nextSteps = [
[
[
'Commit your changes before deploying or use the ',
{command: '--force'},
' flag to deploy with uncommitted changes.',
],
'Commit your changes before deploying or use the',
{command: '--force'},
'flag to deploy with uncommitted changes.',
],
);
];

const {files} = await git({baseDir: root}).status();

if (files.length) {
const formattedFiles = files
.map(
({path, index, working_dir}: FileStatusResult) =>
`${index}${working_dir} ${path}`,
)
.join('\n');

errorMessage += `:\n\n${formattedFiles}`;

packageManagers.forEach(({name, lockfile, installCommand}) => {
if (formattedFiles.includes(lockfile)) {
nextSteps.push([
`If you are using ${name}, try running`,
{command: installCommand},
`to avoid changes to ${lockfile}.`,
]);
}
});
}

throw new AbortError(errorMessage, null, nextSteps);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/package-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export const packageManagers: PackageManager[] = [
{
name: 'bun',
lockfile: 'bun.lockb',
installCommand: 'bun install',
installCommand: 'bun install --frozen-lockfile',
},
];

0 comments on commit 2b0188e

Please sign in to comment.