import type { ShellRunner } from '../../lib/shell.js'; export interface WorktreeConfig { repoRoot: string; path: string; branch: string; /** Commit-ish to branch from when the branch does not already exist. */ startPoint: string; } export interface WorktreeStartPoint { ref: string; warning?: string; } /** * Resolve the worktrees directory. * Uses DEVBOX_WORKTREES_DIR if set, otherwise defaults to dirname(repoRoot). */ export declare function resolveWorktreesDir(repoRoot: string, env: Record): string; /** * Compute the worktree path for a branch. * Pattern: /- */ export declare function branchToPath(worktreesDir: string, repoName: string, branch: string): string; /** * Check if a local branch exists. */ export declare function branchExists(runner: ShellRunner, repoRoot: string, branch: string): Promise; /** * Strip git ref prefixes down to the branch name. * * `git symbolic-ref refs/remotes/origin/HEAD` prints * `refs/remotes/origin/main` (not `refs/heads/main`). Local HEAD prints * `refs/heads/main`. Keep slashes in the remainder (`release/1.x`). */ export declare function stripBranchRef(ref: string): string; /** * Resolve the repo's default branch. * * Tries `git symbolic-ref refs/remotes/origin/HEAD` first (the upstream * default), falls back to `git symbolic-ref HEAD` (the local default), and * finally defaults to 'main' if neither resolves (e.g. a fresh repo with no * remote). */ export declare function defaultBranch(runner: ShellRunner, repoRoot: string): Promise; /** * Pick the commit a new worktree should start from. * * After a successful fetch, prefer `origin/` so the box is not * stuck on a stale local default branch. `DEVBOX_START_POINT=local` keeps * the old behavior. Fetch failure or a missing origin ref falls back to * the local default. Local-only commits are left on local `main`; the new * branch still starts from origin, with a warning. */ export declare function resolveWorktreeStartPoint(runner: ShellRunner, repoRoot: string, env: Record, opts: { fetched: boolean; }): Promise; export type EnsureWorktreeConfigResult = { status: 'ok'; } | { status: 'copied'; } | { status: 'missing'; message: string; }; /** * Make sure a worktree has the files `devcontainer up` needs. * * `git worktree add` only checks out committed files, so a just-inited repo * (untracked `.devbox/` + `.devcontainer/`) would otherwise boot a worktree * with no `devcontainer.json`. Copy those trees from the source checkout * when the worktree is missing them. */ export declare function ensureWorktreeConfig(repoRoot: string, worktreePath: string): Promise; /** * Create a worktree for a branch. If the branch already exists, reuse it. * If not, create a new branch from `config.startPoint` (typically * `origin/` after fetch). * * Uses --relative-paths so the .git pointer resolves inside the container. */ export declare function createWorktree(runner: ShellRunner, config: WorktreeConfig): Promise; /** * Remove a worktree. Tries `git worktree remove --force`, falls back to rm -rf. * @returns true if the worktree was removed (or didn't exist). */ export declare function removeWorktree(runner: ShellRunner, repoRoot: string, path: string): Promise; /** * Delete a local branch. */ export declare function deleteBranch(runner: ShellRunner, repoRoot: string, branch: string): Promise;