fix(worktrees): default to HEAD when no startPoint provided
- Use git reset --hard HEAD by default when startPoint is not provided or is HEAD - Preserve resetting to the provided startPoint when a concrete value is supplied
This commit is contained in:
@@ -328,7 +328,9 @@ export function GitHubPullRequestPickerDialog({
|
|||||||
throw new Error(`Local branch already exists: ${preferredBranch}`);
|
throw new Error(`Local branch already exists: ${preferredBranch}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await createWorktreeSessionForNewBranchExact(projectDirectory, preferredBranch, headCommitish);
|
const session = await createWorktreeSessionForNewBranchExact(projectDirectory, preferredBranch, headCommitish, {
|
||||||
|
kind: 'pr',
|
||||||
|
});
|
||||||
if (!session?.id) {
|
if (!session?.id) {
|
||||||
throw new Error('Failed to create PR worktree session');
|
throw new Error('Failed to create PR worktree session');
|
||||||
}
|
}
|
||||||
@@ -341,12 +343,12 @@ export function GitHubPullRequestPickerDialog({
|
|||||||
|
|
||||||
// Switch the new worktree to the PR branch and delete the SDK-created opencode/* branch immediately.
|
// Switch the new worktree to the PR branch and delete the SDK-created opencode/* branch immediately.
|
||||||
// This makes the worktree directly operate on the PR branch.
|
// This makes the worktree directly operate on the PR branch.
|
||||||
const originalBranch = (meta?.branch || session.branch || '').replace(/^refs\/heads\//, '').trim();
|
|
||||||
const commands: string[] = [
|
const commands: string[] = [
|
||||||
// Create local branch from the fetched PR head commit.
|
// Create local branch from the fetched PR head commit.
|
||||||
`git -C ${JSON.stringify(worktreeDir)} switch -c ${JSON.stringify(preferredBranch)} ${JSON.stringify(headCommitish)}`,
|
`git -C ${JSON.stringify(worktreeDir)} switch -c ${JSON.stringify(preferredBranch)} ${JSON.stringify(headCommitish)}`,
|
||||||
];
|
];
|
||||||
if (originalBranch && originalBranch.startsWith('opencode/')) {
|
const originalBranch = (meta?.branch || session.branch || '').replace(/^refs\/heads\//, '').trim();
|
||||||
|
if (meta?.kind === 'pr' && originalBranch && originalBranch.startsWith('opencode/')) {
|
||||||
commands.push(`git -C ${JSON.stringify(projectDirectory)} branch -D ${JSON.stringify(originalBranch)}`);
|
commands.push(`git -C ${JSON.stringify(projectDirectory)} branch -D ${JSON.stringify(originalBranch)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,6 +396,7 @@ export function GitHubPullRequestPickerDialog({
|
|||||||
branch: preferredBranch,
|
branch: preferredBranch,
|
||||||
label: preferredBranch,
|
label: preferredBranch,
|
||||||
createdFromBranch: pr.base,
|
createdFromBranch: pr.base,
|
||||||
|
kind: 'pr' as const,
|
||||||
});
|
});
|
||||||
|
|
||||||
return { id: session.id };
|
return { id: session.id };
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ export async function createWorktreeSession(): Promise<{ id: string } | null> {
|
|||||||
const createdMetadata = {
|
const createdMetadata = {
|
||||||
...metadata,
|
...metadata,
|
||||||
createdFromBranch: startPoint ?? 'HEAD',
|
createdFromBranch: startPoint ?? 'HEAD',
|
||||||
|
kind: 'standard' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get worktree status
|
// Get worktree status
|
||||||
@@ -271,6 +272,7 @@ export async function createWorktreeSessionForBranch(
|
|||||||
const createdMetadata = {
|
const createdMetadata = {
|
||||||
...metadata,
|
...metadata,
|
||||||
createdFromBranch: branchName,
|
createdFromBranch: branchName,
|
||||||
|
kind: 'standard' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get worktree status
|
// Get worktree status
|
||||||
@@ -394,7 +396,7 @@ export async function createWorktreeSessionForNewBranch(
|
|||||||
projectDirectory: string,
|
projectDirectory: string,
|
||||||
preferredBranchName: string,
|
preferredBranchName: string,
|
||||||
startPoint: string,
|
startPoint: string,
|
||||||
options?: { allowSuffix?: boolean }
|
options?: { allowSuffix?: boolean; kind?: 'pr' | 'standard' }
|
||||||
): Promise<{ id: string; branch: string } | null> {
|
): Promise<{ id: string; branch: string } | null> {
|
||||||
if (isCreatingWorktreeSession) {
|
if (isCreatingWorktreeSession) {
|
||||||
return null;
|
return null;
|
||||||
@@ -425,6 +427,7 @@ export async function createWorktreeSessionForNewBranch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const allowSuffix = options?.allowSuffix !== false;
|
const allowSuffix = options?.allowSuffix !== false;
|
||||||
|
const kind = options?.kind ?? 'standard';
|
||||||
|
|
||||||
const projectRef = resolveProjectRef(projectDirectory);
|
const projectRef = resolveProjectRef(projectDirectory);
|
||||||
if (!projectRef) {
|
if (!projectRef) {
|
||||||
@@ -444,6 +447,7 @@ export async function createWorktreeSessionForNewBranch(
|
|||||||
const createdMetadata = {
|
const createdMetadata = {
|
||||||
...metadata,
|
...metadata,
|
||||||
createdFromBranch: start,
|
createdFromBranch: start,
|
||||||
|
kind,
|
||||||
};
|
};
|
||||||
|
|
||||||
const status = await getWorktreeStatus(metadata.path).catch(() => undefined);
|
const status = await getWorktreeStatus(metadata.path).catch(() => undefined);
|
||||||
@@ -543,7 +547,11 @@ export async function createWorktreeSessionForNewBranch(
|
|||||||
export async function createWorktreeSessionForNewBranchExact(
|
export async function createWorktreeSessionForNewBranchExact(
|
||||||
projectDirectory: string,
|
projectDirectory: string,
|
||||||
branchName: string,
|
branchName: string,
|
||||||
startPoint: string
|
startPoint: string,
|
||||||
|
options?: { kind?: 'pr' | 'standard' }
|
||||||
): Promise<{ id: string; branch: string } | null> {
|
): Promise<{ id: string; branch: string } | null> {
|
||||||
return createWorktreeSessionForNewBranch(projectDirectory, branchName, startPoint, { allowSuffix: false });
|
return createWorktreeSessionForNewBranch(projectDirectory, branchName, startPoint, {
|
||||||
|
allowSuffix: false,
|
||||||
|
kind: options?.kind,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ export const buildSdkStartCommand = (args: {
|
|||||||
const startPoint = typeof args.startPoint === 'string' ? args.startPoint.trim() : '';
|
const startPoint = typeof args.startPoint === 'string' ? args.startPoint.trim() : '';
|
||||||
if (startPoint && startPoint !== 'HEAD') {
|
if (startPoint && startPoint !== 'HEAD') {
|
||||||
commands.push(`git reset --hard ${shellQuote(startPoint)}`);
|
commands.push(`git reset --hard ${shellQuote(startPoint)}`);
|
||||||
|
} else {
|
||||||
|
commands.push('git reset --hard HEAD');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const raw of args.setupCommands) {
|
for (const raw of args.setupCommands) {
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ export const useMultiRunStore = create<MultiRunStore>()(
|
|||||||
const enrichedMetadata = {
|
const enrichedMetadata = {
|
||||||
...worktreeMetadata,
|
...worktreeMetadata,
|
||||||
createdFromBranch: startPoint ?? 'HEAD',
|
createdFromBranch: startPoint ?? 'HEAD',
|
||||||
|
kind: 'standard' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Session title format: groupSlug/provider/model (or groupSlug/provider/model/index for duplicates)
|
// Session title format: groupSlug/provider/model (or groupSlug/provider/model/index for duplicates)
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ export interface WorktreeMetadata {
|
|||||||
/** SDK worktree name (slug), if available. */
|
/** SDK worktree name (slug), if available. */
|
||||||
name?: string;
|
name?: string;
|
||||||
|
|
||||||
|
kind?: 'pr' | 'standard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Branch/ref this worktree was created from (intended integration target).
|
* Branch/ref this worktree was created from (intended integration target).
|
||||||
* For SDK worktrees this is typically the user-selected base branch.
|
* For SDK worktrees this is typically the user-selected base branch.
|
||||||
|
|||||||
Reference in New Issue
Block a user