Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit aa50a93

Browse files
committed
fix: check if we're already on a branch before switching to it.
1 parent 932e7d6 commit aa50a93

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

‎apps/array/src/main/services/workspace/service.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,26 @@ export class WorkspaceService extends TypedEventEmitter<WorkspaceServiceEvents>
136136
// try to create the branch, if it already exists just switch to it
137137
if (branch) {
138138
try {
139-
log.info(`Creating/switching to branch ${branch} for task ${taskId}`);
140-
try {
141-
await execAsync(`git checkout -b "${branch}"`, { cwd: folderPath });
142-
log.info(`Created and switched to new branch ${branch}`);
143-
} catch (_error) {
144-
await execAsync(`git checkout "${branch}"`, { cwd: folderPath });
145-
log.info(`Switched to existing branch ${branch}`);
139+
// Check if already on the target branch
140+
const { stdout: currentBranch } = await execAsync(
141+
"git rev-parse --abbrev-ref HEAD",
142+
{ cwd: folderPath },
143+
);
144+
if (currentBranch.trim() === branch) {
145+
log.info(`Already on branch ${branch}, skipping checkout`);
146+
} else {
147+
log.info(
148+
`Creating/switching to branch ${branch} for task ${taskId}`,
149+
);
150+
try {
151+
await execAsync(`git checkout -b "${branch}"`, {
152+
cwd: folderPath,
153+
});
154+
log.info(`Created and switched to new branch ${branch}`);
155+
} catch (_error) {
156+
await execAsync(`git checkout "${branch}"`, { cwd: folderPath });
157+
log.info(`Switched to existing branch ${branch}`);
158+
}
146159
}
147160
} catch (error) {
148161
const message = `Could not switch to branch "${branch}". Please commit or stash your changes first.`;

0 commit comments

Comments
 (0)