{"record":{"id":"bc29bff5460fa87c","repo":"eyaltoledano/claude-task-master","slug":"projectroot-is-required-for-getcurrentbranch-bc29bf","errorCode":null,"errorMessage":"projectRoot is required for getCurrentBranch","messagePattern":"projectRoot is required for getCurrentBranch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/utils/git-utils.js","lineNumber":40,"sourceCode":"\t\tthrow new Error('projectRoot is required for isGitRepository');\n\t}\n\n\ttry {\n\t\tawait execAsync('git rev-parse --git-dir', { cwd: projectRoot });\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 * @param {string} projectRoot - Directory to check (required)\n * @returns {Promise<string|null>} Current branch name or null if not in git repo\n */\nasync function getCurrentBranch(projectRoot) {\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 * 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) {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/utils/git-utils.js#L22-L58","documentation":"getCurrentBranch() runs 'git rev-parse --abbrev-ref HEAD' in projectRoot to read the current branch name. It throws when projectRoot is falsy, since the git command needs a working directory; without a repo it would otherwise return null.","triggerScenarios":"Calling getCurrentBranch() with no argument, or with an empty/undefined projectRoot variable propagated from failed root detection.","commonSituations":"Displaying the current branch in CLI output when the projectRoot was not resolved; invoking git-utils from a script where args were reordered; empty environment variable for the project path.","solutions":["Call with an explicit root: await getCurrentBranch(process.cwd())","Resolve/validate projectRoot before the call and skip git features if absent","Fix the upstream caller that passes undefined","Guard: if (!projectRoot) return null instead of calling"],"exampleFix":"// before\nconst branch = await getCurrentBranch();\n// after\nconst branch = projectRoot ? await getCurrentBranch(projectRoot) : null;","handlingStrategy":"validation","validationCode":"if (!projectRoot) {\n  throw new TypeError('getCurrentBranch requires a projectRoot');\n}\nconst branch = await getCurrentBranch(projectRoot);","typeGuard":"function hasProjectRoot(p) {\n  return typeof p === 'string' && p.trim().length > 0;\n}","tryCatchPattern":"try {\n  const branch = await getCurrentBranch(projectRoot);\n} catch (err) {\n  if (err.message.includes('projectRoot is required')) {\n    return null;\n  }\n  throw err;\n}","preventionTips":["Pass projectRoot (or process.cwd()) explicitly to every git-utils function","Validate root resolution once at startup and reuse it","Guard UI/display code to skip git info when root is unknown","Keep argument order consistent when wrapping these helpers"],"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"}