Skip to content

Commit 955d1d2

Browse files
committed
Fix: Use trunkBranch parameter in SSHRuntime instead of HEAD
Previously, SSHRuntime ignored the trunkBranch parameter and always created new branches from HEAD. This caused new branches to be created from whatever HEAD was pointing to, rather than the specified trunk. Changes: - Use trunkBranch parameter instead of _trunkBranch (unused variable) - Pass trunkBranch to 'git checkout -b' instead of hardcoded 'HEAD' - Update comment to reflect correct behavior This brings SSHRuntime in line with LocalRuntime, which correctly uses the trunkBranch parameter when creating new branches via 'git worktree add -b'. Fixes the integration test: 'creates new branch from specified trunk branch, not from default branch'
1 parent a64075c commit 955d1d2

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/runtime/SSHRuntime.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,7 @@ export class SSHRuntime implements Runtime {
586586
}
587587

588588
async initWorkspace(params: WorkspaceInitParams): Promise<WorkspaceInitResult> {
589-
const {
590-
projectPath,
591-
branchName,
592-
trunkBranch: _trunkBranch,
593-
workspacePath,
594-
initLogger,
595-
} = params;
589+
const { projectPath, branchName, trunkBranch, workspacePath, initLogger } = params;
596590

597591
try {
598592
// 1. Sync project to remote (opportunistic rsync with scp fallback)
@@ -611,11 +605,9 @@ export class SSHRuntime implements Runtime {
611605
initLogger.logStep("Files synced successfully");
612606

613607
// 2. Checkout branch remotely
614-
// Note: After git clone, HEAD is already checked out to the default branch from the bundle
615-
// We create new branches from HEAD instead of the trunkBranch name to avoid issues
616-
// where the local repo's trunk name doesn't match the cloned repo's default branch
608+
// If branch exists, check it out; otherwise create it from the specified trunk branch
617609
initLogger.logStep(`Checking out branch: ${branchName}`);
618-
const checkoutCmd = `(git checkout ${JSON.stringify(branchName)} 2>/dev/null || git checkout -b ${JSON.stringify(branchName)} HEAD)`;
610+
const checkoutCmd = `(git checkout ${JSON.stringify(branchName)} 2>/dev/null || git checkout -b ${JSON.stringify(branchName)} ${JSON.stringify(trunkBranch)})`;
619611

620612
const checkoutStream = await this.exec(checkoutCmd, {
621613
cwd: workspacePath, // Use the full workspace path for git operations

0 commit comments

Comments
 (0)