Unverified 提交 8a53b927 authored 作者: Adekunle James Adeniji's avatar Adekunle James Adeniji 提交者: GitHub

Fix (#2354): Implement auto-commit for local changes before preparing GitHub branch (#2373)

Closes #2354 <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2373"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Automatically commits local changes before preparing a GitHub branch, preventing failures on dirty repos and making branch setup reliable. Closes #2354. - **Bug Fixes** - Auto-add and commit pending changes in prepareLocalBranch. - Block with a clear error if a merge or rebase is in progress. - Use locking and ensureCleanWorkspace to keep operations atomic and clean. - Export prepareLocalBranch for reuse. <sup>Written for commit b3af874e41856d47d397343ded7e278336ad0d92. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
上级 211549af
......@@ -17,6 +17,8 @@ import {
gitListBranches,
gitListRemoteBranches,
isGitStatusClean,
gitAddAll,
gitCommit,
getCurrentCommitHash,
isGitMergeInProgress,
isGitRebaseInProgress,
......@@ -108,7 +110,7 @@ export async function getGithubUser(): Promise<GithubUser | null> {
}
}
async function prepareLocalBranch({
export async function prepareLocalBranch({
appId,
branch,
remoteUrl,
......@@ -156,7 +158,42 @@ async function prepareLocalBranch({
// Use locking to prevent race conditions when multiple operations attempt to modify the repository
// This ensures atomicity and prevents conflicts between concurrent operations
await withLock(appId, async () => {
// Check for uncommitted changes
const isClean = await isGitStatusClean({ path: appPath });
if (!isClean) {
if (isGitMergeInProgress({ path: appPath })) {
throw new Error(
"Cannot auto-commit changes because a merge is in progress. " +
"Please complete or abort the merge and try again.",
);
}
if (isGitRebaseInProgress({ path: appPath })) {
throw new Error(
"Cannot auto-commit changes because a rebase is in progress. " +
"Please complete or abort the rebase and try again.",
);
}
try {
await gitAddAll({ path: appPath });
const commitHash = await gitCommit({
path: appPath,
message:
"chore: auto-commit local changes before connecting to GitHub",
});
logger.info(
`[GitHub Handler] Auto-committed local changes (${commitHash}) before preparing branch '${targetBranch}'.`,
);
} catch (commitError) {
logger.error(
"[GitHub Handler] Failed to auto-commit local changes before preparing branch:",
commitError,
);
throw new Error(
"Failed to auto-commit uncommitted changes. Please commit or stash your changes manually and try again.",
);
}
}
await ensureCleanWorkspace(appPath, `preparing branch '${targetBranch}'`);
// List branches and check if target branch exists
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论