diff --git a/src/components/git/PullRequestDialog.tsx b/src/components/git/PullRequestDialog.tsx index 6716666b..1dbb6f16 100644 --- a/src/components/git/PullRequestDialog.tsx +++ b/src/components/git/PullRequestDialog.tsx @@ -276,6 +276,10 @@ export function PullRequestDialog({ // IMPORTANT: Create branch FIRST, then commit to it // This ensures main and feature-branch have different commits + // Check if there are uncommitted changes BEFORE branching + const statusMatrix = await git.statusMatrix({ dir: projectPath }); + const hasUncommittedChanges = statusMatrix.some(([, head, workdir]) => head !== workdir); + // Create and checkout the new branch from current HEAD await git.branch({ dir: projectPath, @@ -286,10 +290,7 @@ export function PullRequestDialog({ branchToUse = featureBranchName; console.log(`Successfully created and checked out branch: ${featureBranchName}`); - // Check if there are uncommitted changes that need to be committed to this branch - const statusMatrix = await git.statusMatrix({ dir: projectPath }); - const hasUncommittedChanges = statusMatrix.some(([, head, workdir]) => head !== workdir); - + // If there were uncommitted changes, commit them now to the new branch if (hasUncommittedChanges) { console.log('Found uncommitted changes, committing to new branch'); @@ -315,17 +316,9 @@ export function PullRequestDialog({ description: `Created '${featureBranchName}' with your changes committed`, }); } else { - // No uncommitted changes - check if this branch differs from main - const mainCommit = await git.resolveRef({ dir: projectPath, ref: `refs/heads/${currentBranch}` }); - const branchCommit = await git.resolveRef({ dir: projectPath, ref: 'HEAD' }); - - if (mainCommit === branchCommit) { - throw new Error( - `No changes to submit.\n\n` + - `You need to have committed changes that differ from the '${currentBranch}' branch.\n\n` + - `Please make some changes and commit them before creating a PR.` - ); - } + // No uncommitted changes - the branch should already differ from main + // (user must have committed changes to main already) + console.log('No uncommitted changes, branch created from existing commits'); toast({ title: 'Feature branch created', diff --git a/src/components/git/PullRequestForm.tsx b/src/components/git/PullRequestForm.tsx index 974fe651..9a5d232c 100644 --- a/src/components/git/PullRequestForm.tsx +++ b/src/components/git/PullRequestForm.tsx @@ -206,7 +206,11 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq console.log(`Creating feature branch: ${featureBranchName}`); try { - // Create branch first + // Check for uncommitted changes BEFORE creating branch + const statusMatrix = await git.statusMatrix({ dir: projectPath }); + const hasUncommittedChanges = statusMatrix.some(([, head, workdir]) => head !== workdir); + + // Create and checkout branch first await git.branch({ dir: projectPath, ref: featureBranchName, @@ -216,10 +220,7 @@ export function PullRequestForm({ projectId, currentBranch, remoteUrl }: PullReq branchToUse = featureBranchName; console.log(`Successfully created and checked out branch: ${featureBranchName}`); - // Check if there are uncommitted changes to commit to this branch - const statusMatrix = await git.statusMatrix({ dir: projectPath }); - const hasUncommittedChanges = statusMatrix.some(([, head, workdir]) => head !== workdir); - + // If there were uncommitted changes, commit them to the new branch if (hasUncommittedChanges) { console.log('Committing changes to new branch');