{"record":{"id":"228c0d543833c8dc","repo":"eyaltoledano/claude-task-master","slug":"projectroot-is-required-for-getcurrentbranch","errorCode":null,"errorMessage":"projectRoot is required for getCurrentBranch","messagePattern":"projectRoot is required for getCurrentBranch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/common/utils/git-utils.ts","lineNumber":62,"sourceCode":"\ttry {\n\t\texecSync('git rev-parse --git-dir', {\n\t\t\tcwd: projectRoot,\n\t\t\tstdio: 'ignore'\n\t\t});\n\t\treturn true;\n\t} catch (error) {\n\t\treturn false;\n\t}\n}\n\n/**\n * Get the current git branch name\n */\nexport async function getCurrentBranch(\n\tprojectRoot: string\n): Promise<string | null> {\n\tif (!projectRoot) {\n\t\tthrow new Error('projectRoot is required for getCurrentBranch');\n\t}\n\n\ttry {\n\t\tconst { stdout } = await execAsync('git rev-parse --abbrev-ref HEAD', {\n\t\t\tcwd: projectRoot\n\t\t});\n\t\treturn stdout.trim();\n\t} catch (error) {\n\t\treturn null;\n\t}\n}\n\n/**\n * Synchronous get current git branch name\n */\nexport function getCurrentBranchSync(projectRoot: string): string | null {\n\tif (!projectRoot) {\n\t\treturn null;","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/common/utils/git-utils.ts#L44-L80","documentation":"getCurrentBranch executes 'git rev-parse --abbrev-ref HEAD' with cwd set to projectRoot; an empty projectRoot makes that impossible, so the guard throws this error before shelling out. It is a fail-fast argument check for the branch-lookup helper.","triggerScenarios":"Calling getCurrentBranch(undefined) or '' — usually projectRoot was never resolved from config or CLI args; also triggered indirectly via the currentBranch/defaultBranch wrappers when they receive an empty root.","commonSituations":"Running git-dependent commands outside a configured project; config files missing the project root key; race where root detection failed silently earlier and '' propagated downstream.","solutions":["Supply the resolved project directory: getCurrentBranch(projectRoot || process.cwd())","Ensure the caller resolved projectRoot before invoking branch helpers (resolve with path.resolve(...))","Fix config loading so the project root key is always populated","If callers cannot guarantee a root, guard: if (!projectRoot) return null; instead of calling"],"exampleFix":"// before\nconst branch = await getCurrentBranch(undefined as any);\n// after\nconst root = projectRoot || process.cwd();\nconst branch = await getCurrentBranch(root);","handlingStrategy":"validation","validationCode":"if (typeof projectRoot !== 'string' || !projectRoot.trim()) {\n  throw new Error('getCurrentBranch needs a non-empty projectRoot');\n}\n// optionally verify it is a repo first:\nif (!(await isGitRepository(projectRoot))) return null;","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  const branch = await getCurrentBranch(projectRoot);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('getCurrentBranch')) {\n    console.error('Missing projectRoot; defaulting to process.cwd().');\n    return getCurrentBranch(process.cwd());\n  }\n  throw err;\n}","preventionTips":["Default projectRoot to process.cwd() at the entry point of your script/CLI","Log or assert projectRoot before calling branch helpers","Fix config loaders so projectRoot cannot be empty string","Use currentBranch wrapper consistently so root handling is centralized"],"tags":["git","argument-validation"],"backgroundTag":"missing-required-parameter","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}