Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class ChatSessionWorktreeService extends Disposable implements IChatSessi

const autoCommit = this.configurationService.getConfig<boolean>(ConfigKey.Advanced.CLIAutoCommitEnabled);

let baseCommit: string | undefined = undefined;
const branch = await this.generateBranchName(branchName, activeRepository);

// When a base branch is provided, we attempt to resolve it, to see whether it has an
Expand All @@ -82,8 +83,19 @@ export class ChatSessionWorktreeService extends Disposable implements IChatSessi
// Attempt to resolve the provided base branch
const branchDetails = await this.gitService.getBranch(activeRepository.rootUri, baseBranch);
if (branchDetails?.upstream?.remote && branchDetails.upstream?.name) {
// If the base branch has an upstream, use it as the base for the worktree
baseBranch = `${branchDetails.upstream.remote}/${branchDetails.upstream.name}`;
const upstreamBranchName = `${branchDetails.upstream.remote}/${branchDetails.upstream.name}`;

try {
// Attempt to resolve the upstream branch before using it as the base for the worktree
const upstreamBranch = await this.gitService.getBranch(activeRepository.rootUri, upstreamBranchName);
if (upstreamBranch) {
baseBranch = upstreamBranchName;
baseCommit = upstreamBranch.commit;
}
Comment thread
lszomoru marked this conversation as resolved.
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
this.logService.warn(`[ChatSessionWorktreeService][_createWorktree] Failed to resolve upstream branch ${upstreamBranchName}. Error: ${errorMessage}`);
}
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
Expand All @@ -97,8 +109,7 @@ export class ChatSessionWorktreeService extends Disposable implements IChatSessi
const baseBranchName = baseBranch ?? activeRepository.headBranchName;
const baseBranchProtected = await this.gitService.isBranchProtected(activeRepository.rootUri, baseBranchName);

let baseCommit: string | undefined = undefined;
if (baseBranch) {
if (baseBranch && !baseCommit) {
const refs = await this.gitService.getRefs(activeRepository.rootUri, { pattern: `refs/heads/${baseBranch}` });
baseCommit = refs.length === 1 && refs[0].commit ? refs[0].commit : undefined;
}
Expand Down
Loading