fix: fetch latest remote before worktree creation & improve settings spacing (#105)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Neil
2026-03-25 22:16:11 -07:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 4c0eee235b
commit 0785dd7b7b
2 changed files with 84 additions and 76 deletions
+13
View File
@@ -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
@@ -133,7 +133,7 @@ export function RepositoryPane({
return (
<div className="space-y-8">
<section className="space-y-4">
<section className="space-y-6">
<div className="flex items-start justify-between gap-4">
<div className="space-y-1">
<h2 className="text-sm font-semibold">Identity</h2>
@@ -186,84 +186,79 @@ export function RepositoryPane({
</div>
</div>
<div className="space-y-2">
<div className="space-y-3">
<Label className="text-sm">Default Worktree Base</Label>
<div className="rounded-xl border bg-background/80 p-4 shadow-sm">
<div className="flex flex-wrap items-center justify-between gap-2">
<div>
<div className="text-sm font-medium text-foreground">{effectiveBaseRef}</div>
<p className="text-xs text-muted-foreground">
{repo.worktreeBaseRef
? 'Pinned for this repo'
: `Following primary branch (${defaultBaseRef})`}
</p>
</div>
<Button
variant="outline"
size="sm"
onClick={() => {
setBaseRefQuery('')
setBaseRefResults([])
updateRepo(repo.id, {
worktreeBaseRef: undefined
})
}}
disabled={!repo.worktreeBaseRef}
>
Use Primary
</Button>
<div className="flex flex-wrap items-center justify-between gap-2">
<div>
<div className="text-sm font-medium text-foreground">{effectiveBaseRef}</div>
<p className="text-xs text-muted-foreground">
{repo.worktreeBaseRef
? 'Pinned for this repo'
: `Following primary branch (${defaultBaseRef})`}
</p>
</div>
<div className="mt-4 space-y-2">
<Input
value={baseRefQuery}
onChange={(e) => setBaseRefQuery(e.target.value)}
placeholder="Search branches by name..."
className="max-w-md"
/>
<p className="text-xs text-muted-foreground">Type at least 2 characters.</p>
</div>
{isSearchingBaseRefs ? (
<p className="mt-3 text-xs text-muted-foreground">Searching branches...</p>
) : null}
{!isSearchingBaseRefs && baseRefQuery.trim().length >= 2 ? (
baseRefResults.length > 0 ? (
<ScrollArea className="mt-3 h-48 rounded-md border">
<div className="p-1">
{baseRefResults.map((ref) => (
<button
key={ref}
onClick={() => {
setBaseRefQuery(ref)
setBaseRefResults([])
updateRepo(repo.id, {
worktreeBaseRef: ref
})
}}
className={`flex w-full items-center justify-between rounded-sm px-3 py-2 text-left text-sm transition-colors hover:bg-muted/60 ${
repo.worktreeBaseRef === ref
? 'bg-accent text-accent-foreground'
: 'text-foreground'
}`}
>
<span className="truncate">{ref}</span>
{repo.worktreeBaseRef === ref ? (
<span className="text-[10px] uppercase tracking-[0.18em]">Current</span>
) : null}
</button>
))}
</div>
</ScrollArea>
) : (
<p className="mt-3 text-xs text-muted-foreground">No matching branches found.</p>
)
) : null}
<Button
variant="outline"
size="sm"
onClick={() => {
setBaseRefQuery('')
setBaseRefResults([])
updateRepo(repo.id, {
worktreeBaseRef: undefined
})
}}
disabled={!repo.worktreeBaseRef}
>
Use Primary
</Button>
</div>
<p className="text-xs text-muted-foreground">
New worktrees default to the repo primary branch unless you pin a different base here.
</p>
<div className="space-y-2">
<Input
value={baseRefQuery}
onChange={(e) => setBaseRefQuery(e.target.value)}
placeholder="Search branches by name..."
className="max-w-md"
/>
<p className="text-xs text-muted-foreground">Type at least 2 characters.</p>
</div>
{isSearchingBaseRefs ? (
<p className="text-xs text-muted-foreground">Searching branches...</p>
) : null}
{!isSearchingBaseRefs && baseRefQuery.trim().length >= 2 ? (
baseRefResults.length > 0 ? (
<ScrollArea className="h-48 rounded-md border">
<div className="p-1">
{baseRefResults.map((ref) => (
<button
key={ref}
onClick={() => {
setBaseRefQuery(ref)
setBaseRefResults([])
updateRepo(repo.id, {
worktreeBaseRef: ref
})
}}
className={`flex w-full items-center justify-between rounded-sm px-3 py-2 text-left text-sm transition-colors hover:bg-muted/60 ${
repo.worktreeBaseRef === ref
? 'bg-accent text-accent-foreground'
: 'text-foreground'
}`}
>
<span className="truncate">{ref}</span>
{repo.worktreeBaseRef === ref ? (
<span className="text-[10px] uppercase tracking-[0.18em]">Current</span>
) : null}
</button>
))}
</div>
</ScrollArea>
) : (
<p className="text-xs text-muted-foreground">No matching branches found.</p>
)
) : null}
</div>
</section>