From 99e6592abc5a01cab807a3e4391148e913dd7c26 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Wed, 11 Jun 2025 15:42:10 -0700 Subject: [PATCH] commit upgrade (#391) --- e2e-tests/select_component.spec.ts | 2 ++ src/ipc/handlers/app_upgrade_handlers.ts | 19 ++++++++++++++++++- src/ipc/utils/git_utils.ts | 12 +++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/e2e-tests/select_component.spec.ts b/e2e-tests/select_component.spec.ts index 7465171..d01b47f 100644 --- a/e2e-tests/select_component.spec.ts +++ b/e2e-tests/select_component.spec.ts @@ -61,6 +61,8 @@ testSkipIfWindows("upgrade app to select component", async ({ po }) => { await po.expectNoAppUpgrades(); await po.snapshotAppFiles(); await po.clickOpenInChatButton(); + // There should be another version from the upgrade being committed. + await expect(po.page.getByText("Version 2")).toBeVisible(); await po.clickPreviewPickElement(); diff --git a/src/ipc/handlers/app_upgrade_handlers.ts b/src/ipc/handlers/app_upgrade_handlers.ts index 8bf72b3..744469d 100644 --- a/src/ipc/handlers/app_upgrade_handlers.ts +++ b/src/ipc/handlers/app_upgrade_handlers.ts @@ -8,6 +8,7 @@ import { getDyadAppPath } from "../../paths/paths"; import fs from "node:fs"; import path from "node:path"; import { spawn } from "node:child_process"; +import { gitAddAll, gitCommit } from "../utils/git_utils"; const logger = log.scope("app_upgrade_handlers"); const handle = createLoggedHandler(logger); @@ -109,7 +110,7 @@ async function applyComponentTagger(appPath: string) { await fs.promises.writeFile(viteConfigPath, content); // Install the dependency - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { logger.info("Installing component-tagger dependency"); const process = spawn( "pnpm add -D @dyad-sh/react-vite-component-tagger || npm install --save-dev --legacy-peer-deps @dyad-sh/react-vite-component-tagger", @@ -138,6 +139,22 @@ async function applyComponentTagger(appPath: string) { reject(err); }); }); + + // Commit changes + try { + logger.info("Staging and committing changes"); + await gitAddAll({ path: appPath }); + await gitCommit({ + path: appPath, + message: "[dyad] add Dyad component tagger", + }); + logger.info("Successfully committed changes"); + } catch (err) { + logger.warn( + `Failed to commit changes. This may happen if the project is not in a git repository, or if there are no changes to commit.`, + err, + ); + } } export function registerAppUpgradeHandlers() { diff --git a/src/ipc/utils/git_utils.ts b/src/ipc/utils/git_utils.ts index 0e79ce7..46533bf 100644 --- a/src/ipc/utils/git_utils.ts +++ b/src/ipc/utils/git_utils.ts @@ -74,7 +74,7 @@ export async function gitStageToRevert({ return; } - // Safety: refuse to run if the work-tree isn’t clean. + // Safety: refuse to run if the work-tree isn't clean. const { stdout: wtStatus } = await execAsync( `git -C "${path}" status --porcelain`, ); @@ -138,3 +138,13 @@ export async function gitStageToRevert({ }); } } + +export async function gitAddAll({ path }: { path: string }): Promise { + const settings = readSettings(); + if (settings.enableNativeGit) { + await execAsync(`git -C "${path}" add .`); + return; + } else { + return git.add({ fs, dir: path, filepath: "." }); + } +}