worktree: try-catch フォールバックと冗長コメントを削除

This commit is contained in:
nrslib 2026-01-29 09:43:04 +09:00
parent 0ecbf6e56b
commit 83621d689e

View File

@ -42,39 +42,27 @@ function generateTimestamp(): string {
* Priority: * Priority:
* 1. Custom path in options.worktree (string) * 1. Custom path in options.worktree (string)
* 2. worktree_dir from config.yaml (if set) * 2. worktree_dir from config.yaml (if set)
* 3. Default: ../{tree-name} (outside project to avoid Claude Code project detection issues) * 3. Default: ../{tree-name}
*/ */
function resolveWorktreePath(projectDir: string, options: WorktreeOptions): string { function resolveWorktreePath(projectDir: string, options: WorktreeOptions): string {
const timestamp = generateTimestamp(); const timestamp = generateTimestamp();
const slug = slugify(options.taskSlug); const slug = slugify(options.taskSlug);
const dirName = slug ? `${timestamp}-${slug}` : timestamp; const dirName = slug ? `${timestamp}-${slug}` : timestamp;
// Custom path specified in task options
if (typeof options.worktree === 'string') { if (typeof options.worktree === 'string') {
const resolved = path.isAbsolute(options.worktree) return path.isAbsolute(options.worktree)
? options.worktree ? options.worktree
: path.resolve(projectDir, options.worktree); : path.resolve(projectDir, options.worktree);
return resolved;
} }
// Load config to check for worktree_dir setting const globalConfig = loadGlobalConfig();
let worktreeBaseDir: string | undefined; if (globalConfig.worktreeDir) {
try { const baseDir = path.isAbsolute(globalConfig.worktreeDir)
const globalConfig = loadGlobalConfig(); ? globalConfig.worktreeDir
worktreeBaseDir = globalConfig.worktreeDir; : path.resolve(projectDir, globalConfig.worktreeDir);
} catch { return path.join(baseDir, dirName);
// Config not found, use default
} }
if (worktreeBaseDir) {
// Use configured worktree directory
const resolved = path.isAbsolute(worktreeBaseDir)
? worktreeBaseDir
: path.resolve(projectDir, worktreeBaseDir);
return path.join(resolved, dirName);
}
// Default: ../{tree-name} (sibling to project directory)
return path.join(projectDir, '..', dirName); return path.join(projectDir, '..', dirName);
} }