{"record":{"id":"c3cdda2f49ac4991","repo":"eyaltoledano/claude-task-master","slug":"projectroot-is-required-for-getlocalbranches-c3cdda","errorCode":null,"errorMessage":"projectRoot is required for getLocalBranches","messagePattern":"projectRoot is required for getLocalBranches","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/utils/git-utils.js","lineNumber":60,"sourceCode":"\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 * Get list of all local git branches\n * @param {string} projectRoot - Directory to check (required)\n * @returns {Promise<string[]>} Array of branch names\n */\nasync function getLocalBranches(projectRoot) {\n\tif (!projectRoot) {\n\t\tthrow new Error('projectRoot is required for getLocalBranches');\n\t}\n\n\ttry {\n\t\tconst { stdout } = await execAsync(\n\t\t\t'git branch --format=\"%(refname:short)\"',\n\t\t\t{ cwd: projectRoot }\n\t\t);\n\t\treturn stdout\n\t\t\t.trim()\n\t\t\t.split('\\n')\n\t\t\t.filter((branch) => branch.length > 0)\n\t\t\t.map((branch) => branch.trim());\n\t} catch (error) {\n\t\treturn [];\n\t}\n}\n\n/**","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/utils/git-utils.js#L42-L78","documentation":"getLocalBranches() runs 'git branch --format=\"%(refname:short)\"' with cwd set to projectRoot to list local branches. It throws when projectRoot is falsy because the command must be executed inside the target repository.","triggerScenarios":"Calling getLocalBranches() without arguments or with an empty string/null projectRoot, usually from a caller (e.g. the 'branches' command) whose root detection failed.","commonSituations":"Running the branches command outside a project directory; projectRoot passed as undefined after a failed findProjectRoot(); tests calling the helper without a fixture repo path.","solutions":["Pass an explicit path: await getLocalBranches(process.cwd())","Verify you are inside a project/git repo before invoking and surface a clearer message otherwise","Fix the caller that yields an empty projectRoot","Guard the call site: if (!projectRoot) return []"],"exampleFix":"// before\nconst branches = await getLocalBranches();\n// after\nif (!projectRoot) throw new Error('Run this command inside a project directory');\nconst branches = await getLocalBranches(projectRoot);","handlingStrategy":"validation","validationCode":"if (!projectRoot) {\n  throw new TypeError('getLocalBranches requires a projectRoot');\n}\nconst branches = await getLocalBranches(projectRoot);","typeGuard":"function hasProjectRoot(p) {\n  return typeof p === 'string' && p.trim().length > 0;\n}","tryCatchPattern":"try {\n  const branches = await getLocalBranches(projectRoot);\n} catch (err) {\n  if (err.message.includes('projectRoot is required')) {\n    console.error('Run this command inside a project directory.');\n    return [];\n  }\n  throw err;\n}","preventionTips":["Verify the working directory is a project before branch commands","Resolve projectRoot before invoking and abort with a clear message if absent","Avoid destructuring mistakes that drop the root argument","Provide a --project-root style override in scripts"],"tags":["git","argument-validation","project-root"],"backgroundTag":"missing-required-argument","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}