diff --git a/src/main/ipc/worktrees.ts b/src/main/ipc/worktrees.ts index 3c4017678..51a0d6648 100644 --- a/src/main/ipc/worktrees.ts +++ b/src/main/ipc/worktrees.ts @@ -1,5 +1,6 @@ import type { BrowserWindow } from 'electron' import { ipcMain } from 'electron' +import { execFileSync } from 'child_process' import { join, basename, resolve, relative, isAbsolute } from 'path' import type { Store } from '../persistence' import type { Worktree, WorktreeMeta } from '../../shared/types' @@ -86,6 +87,18 @@ export function registerWorktreeHandlers(mainWindow: BrowserWindow, store: Store // Determine base branch const baseBranch = args.baseBranch || repo.worktreeBaseRef || getDefaultBaseRef(repo.path) + // Fetch latest from remote so the worktree starts with up-to-date content + const remote = baseBranch.includes('/') ? baseBranch.split('/')[0] : 'origin' + try { + execFileSync('git', ['fetch', remote], { + cwd: repo.path, + encoding: 'utf-8', + stdio: ['pipe', 'pipe', 'pipe'] + }) + } catch { + // Fetch is best-effort — don't block worktree creation if offline + } + addWorktree(repo.path, worktreePath, branchName, baseBranch) // Re-list to get the freshly created worktree info diff --git a/src/renderer/src/components/settings/RepositoryPane.tsx b/src/renderer/src/components/settings/RepositoryPane.tsx index f24b3fd57..b6fa7418a 100644 --- a/src/renderer/src/components/settings/RepositoryPane.tsx +++ b/src/renderer/src/components/settings/RepositoryPane.tsx @@ -133,7 +133,7 @@ export function RepositoryPane({ return (
- {repo.worktreeBaseRef - ? 'Pinned for this repo' - : `Following primary branch (${defaultBaseRef})`} -
-+ {repo.worktreeBaseRef + ? 'Pinned for this repo' + : `Following primary branch (${defaultBaseRef})`} +
Type at least 2 characters.
-Searching branches...
- ) : null} - - {!isSearchingBaseRefs && baseRefQuery.trim().length >= 2 ? ( - baseRefResults.length > 0 ? ( -No matching branches found.
- ) - ) : null} +- New worktrees default to the repo primary branch unless you pin a different base here. -
+ +Type at least 2 characters.
+Searching branches...
+ ) : null} + + {!isSearchingBaseRefs && baseRefQuery.trim().length >= 2 ? ( + baseRefResults.length > 0 ? ( +No matching branches found.
+ ) + ) : null}