{"record":{"id":"ebe5de942955d94a","repo":"paperclipai/paperclip","slug":"current-directory-is-not-inside-a-git-repository","errorCode":null,"errorMessage":"Current directory is not inside a git repository.","messagePattern":"Current directory is not inside a git repository\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":649,"sourceCode":"    execFileSync(\"git\", [\"check-ref-format\", \"--branch\", value], {\n      cwd,\n      stdio: [\"ignore\", \"pipe\", \"pipe\"],\n    });\n  } catch (error) {\n    throw new Error(`Invalid branch name \"${branchName}\": ${extractExecSyncErrorMessage(error) ?? String(error)}`);\n  }\n  return value;\n}\n\nfunction isPrimaryGitWorktree(cwd: string): boolean {\n  const workspace = detectGitWorkspaceInfo(cwd);\n  return Boolean(workspace && workspace.gitDir === workspace.commonDir);\n}\n\nfunction resolvePrimaryGitRepoRoot(cwd: string): string {\n  const workspace = detectGitWorkspaceInfo(cwd);\n  if (!workspace) {\n    throw new Error(\"Current directory is not inside a git repository.\");\n  }\n  if (workspace.gitDir === workspace.commonDir) {\n    return workspace.root;\n  }\n  return path.resolve(workspace.commonDir, \"..\");\n}\n\nfunction resolveRepairWorktreeDirName(branchName: string): string {\n  const normalized = branchName.trim()\n    .replace(/[^A-Za-z0-9._-]+/g, \"-\")\n    .replace(/-+/g, \"-\")\n    .replace(/^[-._]+|[-._]+$/g, \"\");\n  return normalized || \"worktree\";\n}\n\nfunction detectGitWorkspaceInfo(cwd: string): GitWorkspaceInfo | null {\n  try {\n    const root = execFileSync(\"git\", [\"rev-parse\", \"--show-toplevel\"], {","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/worktree.ts#L631-L667","documentation":"Thrown by resolvePrimaryGitRepoRoot when detectGitWorkspaceInfo returns null, meaning none of the git rev-parse probes (show-toplevel, git-common-dir, git-dir) succeeded. The worktree repair/init flow requires a git repository to anchor the worktree under .paperclip/worktrees.","triggerScenarios":"Running paperclipai worktree commands from a directory that is not inside any git worktree; git is not installed or not on PATH (rev-parse throws); the directory is inside a bare repo with no working tree; filesystem permissions block git from reading .git.","commonSituations":"Running the CLI in /tmp or a non-repo scratch dir; fresh clone where git binary is missing in the container; running inside a bare repository; misconfigured PATH in CI.","solutions":["cd into the cloned Paperclip git repository before running the worktree command.","Ensure the git binary is installed and on PATH (git --version works).","If you intentionally have no repo, initialize one with git init first, or use a flow that does not require git.","Check filesystem permissions allow reading the .git directory."],"exampleFix":"// before: run from /tmp\n// after\ngit clone <repo> paperclip && cd paperclip && paperclipai worktree ...","handlingStrategy":"validation","validationCode":"function isInGitRepo(cwd: string): boolean {\n  try {\n    execFileSync('git', ['rev-parse', '--git-dir'], { cwd, stdio: 'ignore' });\n    return true;\n  } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run worktree commands from inside a clone.","Ensure git is installed and on PATH in CI containers.","Guard the CLI entrypoint with an isInGitRepo(cwd) check."],"tags":["git","worktree","environment","missing-dependency"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}