{"record":{"id":"1f21839ba8abf613","repo":"eyaltoledano/claude-task-master","slug":"projectroot-is-required-for-isgitrepository-1f2183","errorCode":null,"errorMessage":"projectRoot is required for isGitRepository","messagePattern":"projectRoot is required for isGitRepository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/utils/git-utils.js","lineNumber":22,"sourceCode":" * Uses raw git commands and gh CLI for operations\n * MCP-friendly: All functions require projectRoot parameter\n */\n\nimport { exec, execSync } from 'child_process';\nimport fs from 'fs';\nimport path from 'path';\nimport { promisify } from 'util';\n\nconst execAsync = promisify(exec);\n\n/**\n * Check if the specified directory is inside a git repository\n * @param {string} projectRoot - Directory to check (required)\n * @returns {Promise<boolean>} True if inside a git repository\n */\nasync function isGitRepository(projectRoot) {\n\tif (!projectRoot) {\n\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');","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/utils/git-utils.js#L4-L40","documentation":"isGitRepository() checks whether a directory is inside a git repository by running 'git rev-parse --git-dir' with projectRoot as cwd. It throws immediately when projectRoot is falsy because the cwd option is required to know where to run the command.","triggerScenarios":"Calling isGitRepository() or isGitRepository(undefined/null/''), typically when a projectRoot variable was never resolved (e.g. findProjectRoot() returned null) or was not passed through from a caller.","commonSituations":"Running code outside a detected Task Master project so projectRoot resolution failed; a CLI flag/env var supplying the path is empty; calling git-utils helpers from scripts/tests without setting up a root.","solutions":["Pass the project root explicitly: await isGitRepository(process.cwd())","Resolve the project root first with findProjectRoot() and handle a null result before calling","Check the caller that builds projectRoot and fix why it is empty","Default to process.cwd() when no root is configured"],"exampleFix":"// before\nconst inGit = await isGitRepository(projectRoot);\n// after\nconst root = projectRoot || process.cwd();\nconst inGit = await isGitRepository(root);","handlingStrategy":"validation","validationCode":"if (!projectRoot || typeof projectRoot !== 'string') {\n  throw new TypeError('isGitRepository requires a non-empty projectRoot path');\n}\nconst inRepo = await isGitRepository(projectRoot);","typeGuard":"function hasProjectRoot(p) {\n  return typeof p === 'string' && p.trim().length > 0;\n}","tryCatchPattern":"try {\n  const inRepo = await isGitRepository(projectRoot);\n} catch (err) {\n  if (err.message.includes('projectRoot is required')) {\n    console.error('No project root resolved; run inside a project or pass a path.');\n    return false;\n  }\n  throw err;\n}","preventionTips":["Resolve projectRoot via findProjectRoot() and check for null before git calls","Default to process.cwd() when no explicit root is configured","Never call git-utils helpers with variables that may be undefined","Set the project path explicitly in scripts/CI environments"],"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"}