From d13bc84232ef838acb559ed1c2c985ee8aecd14e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 29 Oct 2025 15:10:20 -0500 Subject: [PATCH] Checkout branch with "force" so it updates the tree --- src/components/GitDialog.tsx | 2 ++ src/components/git/BranchManager.tsx | 1 + src/lib/commands/git/checkout.ts | 8 +++++--- src/lib/git.ts | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 2a12c366..9e120a39 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -135,6 +135,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog await git.checkout({ dir: projectPath, ref: branchName, + force: true, }); toast({ @@ -1125,6 +1126,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog await git.checkout({ dir: projectPath, ref: pr.sourceBranch, + force: true, }); await refetchGitStatus(); toast({ diff --git a/src/components/git/BranchManager.tsx b/src/components/git/BranchManager.tsx index 42e0801a..ecb085cf 100644 --- a/src/components/git/BranchManager.tsx +++ b/src/components/git/BranchManager.tsx @@ -213,6 +213,7 @@ export function BranchManager({ projectId, currentBranch, onBranchChange }: Bran await git.checkout({ dir: projectPath, ref: branchName, + force: true, }); toast({ diff --git a/src/lib/commands/git/checkout.ts b/src/lib/commands/git/checkout.ts index 0dc91a2c..ace96b39 100644 --- a/src/lib/commands/git/checkout.ts +++ b/src/lib/commands/git/checkout.ts @@ -97,7 +97,7 @@ export class GitCheckoutCommand implements GitSubcommand { let currentBranch: string | null = null; try { currentBranch = await this.git.currentBranch({ - + dir: this.pwd, }) || null; } catch { @@ -125,6 +125,7 @@ export class GitCheckoutCommand implements GitSubcommand { await this.git.checkout({ dir: this.pwd, ref: branchName, + force: true, }); return createSuccessResult(`Switched to branch '${branchName}'\n`); @@ -149,7 +150,7 @@ export class GitCheckoutCommand implements GitSubcommand { let currentRef: string; try { currentRef = await this.git.resolveRef({ - + dir: this.pwd, ref: 'HEAD', }); @@ -168,6 +169,7 @@ export class GitCheckoutCommand implements GitSubcommand { await this.git.checkout({ dir: this.pwd, ref: branchName, + force: true, }); return createSuccessResult(`Switched to a new branch '${branchName}'\n`); @@ -185,7 +187,7 @@ export class GitCheckoutCommand implements GitSubcommand { // Get the file from HEAD try { await this.git.checkout({ - + dir: this.pwd, ref: 'HEAD', filepaths: [filePath], diff --git a/src/lib/git.ts b/src/lib/git.ts index 6a889957..30efa5ef 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -1066,6 +1066,7 @@ export class Git { fs: this.fs, dir: options.dir, ref: expectedBranch, + force: true, }); } catch (checkoutError) { console.warn(`Failed to checkout branch ${expectedBranch}:`, checkoutError);