Skip to content

Commit 94d934a

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 7a78c15 commit 94d934a

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
@@ -669,13 +669,7 @@ export class SSHRuntime implements Runtime {
669669
}
670670

671671
async initWorkspace(params: WorkspaceInitParams): Promise<WorkspaceInitResult> {
672-
const {
673-
projectPath,
674-
branchName,
675-
trunkBranch: _trunkBranch,
676-
workspacePath,
677-
initLogger,
678-
} = params;
672+
const { projectPath, branchName, trunkBranch, workspacePath, initLogger } = params;
679673

680674
try {
681675
// 1. Sync project to remote (opportunistic rsync with scp fallback)
@@ -694,11 +688,9 @@ export class SSHRuntime implements Runtime {
694688
initLogger.logStep("Files synced successfully");
695689

696690
// 2. Checkout branch remotely
697-
// Note: After git clone, HEAD is already checked out to the default branch from the bundle
698-
// We create new branches from HEAD instead of the trunkBranch name to avoid issues
699-
// where the local repo's trunk name doesn't match the cloned repo's default branch
691+
// If branch exists, check it out; otherwise create it from the specified trunk branch
700692
initLogger.logStep(`Checking out branch: ${branchName}`);
701-
const checkoutCmd = `(git checkout ${shescape.quote(branchName)} 2>/dev/null || git checkout -b ${shescape.quote(branchName)} HEAD)`;
693+
const checkoutCmd = `(git checkout ${shescape.quote(branchName)} 2>/dev/null || git checkout -b ${shescape.quote(branchName)} ${shescape.quote(trunkBranch)})`;
702694

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

0 commit comments

Comments
 (0)