Skip to content

Commit 6567466

Browse files
committed
Fix patch application using 3-way merge and include unstaged changes
1 parent d177ec4 commit 6567466

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

main.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -630,24 +630,24 @@ ipcMain.handle("apply-session-to-project", async (_event, sessionId: string) =>
630630
const patchFilename = `fleetcode-patch-${Date.now()}.patch`;
631631
const patchPath = path.join("/tmp", patchFilename);
632632

633-
// Create git instance for worktree
634-
const worktreeGit = simpleGit(worktreePath);
635-
636-
// Generate patch file from parent branch to current HEAD (includes all commits and staged changes)
637-
// Using diff to capture all changes since divergence from parent branch
638-
const diffCommand = `${parentBranch}...HEAD`;
633+
// Generate patch file from parent branch to current state (includes commits + unstaged changes)
634+
// Using diff against parent branch to capture all changes
639635
const { stdout: patchContent } = await execAsync(
640-
`git diff ${diffCommand}`,
636+
`git diff ${parentBranch}`,
641637
{ cwd: worktreePath }
642638
);
643639

640+
// If patch is empty, there are no changes to apply
641+
if (!patchContent.trim()) {
642+
return { success: false, error: "No changes to apply" };
643+
}
644+
644645
// Write patch to temp file
645646
fs.writeFileSync(patchPath, patchContent);
646647

647-
// Apply patch to original project directory
648-
const projectGit = simpleGit(projectDir);
648+
// Apply patch to original project directory using 3-way merge
649649
try {
650-
await execAsync(`git apply "${patchPath}"`, { cwd: projectDir });
650+
await execAsync(`git apply --3way "${patchPath}"`, { cwd: projectDir });
651651

652652
// Clean up patch file on success
653653
fs.unlinkSync(patchPath);

0 commit comments

Comments
 (0)