mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Fix race condition in auto-branch creation
**Issue:** Branch was being created and immediately checked for differences, but the check was reading the OLD currentBranch ref instead of the newly created branch, causing false "no changes" errors. **Fix:** - Check for uncommitted changes BEFORE creating branch (not after) - Store the status matrix state - Create branch - Commit uncommitted changes to new branch using stored status - Removed the diff check that was using stale ref data **Why This Works:** The statusMatrix check happens before branching, capturing the actual uncommitted state. After branching and committing, we don't need to validate - if there were uncommitted changes, they're now committed to the feature branch. If there weren't, the user must have already committed to main, so the feature branch already differs from upstream/main. This fixes the error loop where it would fail first time, then work second time (because the branch existed on second attempt).
This commit is contained in:
1 parent
428c6b0e2e
commit
ec4e035618
2 files changed
+14
-20
No files matched your search
@@ -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');
|
||||
|
||||
|
||||
Reference in new issue
Block a user