{"record":{"id":"6b56f9ccae368e9c","repo":"eyaltoledano/claude-task-master","slug":"projectroot-is-required-for-getdefaultbranch-6b56f9","errorCode":null,"errorMessage":"projectRoot is required for getDefaultBranch","messagePattern":"projectRoot is required for getDefaultBranch","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/modules/utils/git-utils.js","lineNumber":224,"sourceCode":"\t\tthrow new Error('projectRoot is required for isGitRepositoryRoot');\n\t}\n\n\ttry {\n\t\tconst gitRoot = await getGitRepositoryRoot(projectRoot);\n\t\treturn gitRoot && path.resolve(gitRoot) === path.resolve(projectRoot);\n\t} catch (error) {\n\t\treturn false;\n\t}\n}\n\n/**\n * Get the default branch name for the repository\n * @param {string} projectRoot - Directory to check (required)\n * @returns {Promise<string|null>} Default branch name or null\n */\nasync function getDefaultBranch(projectRoot) {\n\tif (!projectRoot) {\n\t\tthrow new Error('projectRoot is required for getDefaultBranch');\n\t}\n\n\ttry {\n\t\t// Try to get from GitHub first (if gh CLI is available)\n\t\tif (await isGhCliAvailable(projectRoot)) {\n\t\t\tconst repoInfo = await getGitHubRepoInfo(projectRoot);\n\t\t\tif (repoInfo && repoInfo.defaultBranchRef) {\n\t\t\t\treturn repoInfo.defaultBranchRef.name;\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to git remote info\n\t\tconst { stdout } = await execAsync(\n\t\t\t'git symbolic-ref refs/remotes/origin/HEAD',\n\t\t\t{ cwd: projectRoot }\n\t\t);\n\t\treturn stdout.replace('refs/remotes/origin/', '').trim();\n\t} catch (error) {","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/utils/git-utils.js#L206-L242","documentation":"getDefaultBranch() determines the repository's default branch, first via the gh CLI (getGitHubRepoInfo) and then via git remote HEAD fallback. It throws when projectRoot is falsy because all underlying git/gh commands need a working directory.","triggerScenarios":"Calling getDefaultBranch() with a missing/null/'' projectRoot argument, often from the 'defaultBranch' helper whose caller did not resolve the root.","commonSituations":"Determining the base branch for PR creation; projectRoot undefined when running outside a project or in CI without the path configured; argument lost when refactoring the helper chain.","solutions":["Pass an explicit root: await getDefaultBranch(process.cwd())","Resolve and validate projectRoot before calling","Fix the caller that drops the argument","Remember a null return (not a throw) means no default branch could be determined — handle both cases"],"exampleFix":"// before\nconst base = await getDefaultBranch();\n// after\nconst base = projectRoot ? await getDefaultBranch(projectRoot) : 'main';","handlingStrategy":"validation","validationCode":"if (!projectRoot) {\n  throw new TypeError('getDefaultBranch requires a projectRoot');\n}\nconst base = await getDefaultBranch(projectRoot);","typeGuard":"function hasProjectRoot(p) {\n  return typeof p === 'string' && p.trim().length > 0;\n}","tryCatchPattern":"try {\n  const base = await getDefaultBranch(projectRoot);\n} catch (err) {\n  if (err.message.includes('projectRoot is required')) {\n    return 'main';\n  }\n  throw err;\n}","preventionTips":["Resolve projectRoot before any PR/base-branch workflow","Pass process.cwd() as an explicit fallback","Distinguish validation throws from null results (unknown default branch)","Configure the project root explicitly in scripts and CI pipelines"],"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"}