πŸ“„ File detail

utils/getWorktreePathsPortable.ts

🧩 .tsπŸ“ 28 linesπŸ’Ύ 847 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œutils/”, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, …). On the API surface it exposes getWorktreePathsPortable β€” mainly functions, hooks, or classes. Dependencies touch subprocess spawning and Node util helpers.

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

import { execFile as execFileCb } from 'child_process' import { promisify } from 'util' const execFileAsync = promisify(execFileCb)

πŸ“€ Exports (heuristic)

  • getWorktreePathsPortable

πŸ“š External import roots

Package roots from from "…" (relative paths omitted).

  • child_process
  • util

πŸ–₯️ Source preview

import { execFile as execFileCb } from 'child_process'
import { promisify } from 'util'

const execFileAsync = promisify(execFileCb)

/**
 * Portable worktree detection using only child_process β€” no analytics,
 * no bootstrap deps, no execa. Used by listSessionsImpl.ts (SDK) and
 * anywhere that needs worktree paths without pulling in the CLI
 * dependency chain (execa β†’ cross-spawn β†’ which).
 */
export async function getWorktreePathsPortable(cwd: string): Promise<string[]> {
  try {
    const { stdout } = await execFileAsync(
      'git',
      ['worktree', 'list', '--porcelain'],
      { cwd, timeout: 5000 },
    )
    if (!stdout) return []
    return stdout
      .split('\n')
      .filter(line => line.startsWith('worktree '))
      .map(line => line.slice('worktree '.length).normalize('NFC'))
  } catch {
    return []
  }
}