{"record":{"id":"99dbf2e43934db0a","repo":"eyaltoledano/claude-task-master","slug":"projectroot-is-required-for-isbranchcheckedout","errorCode":null,"errorMessage":"projectRoot is required for isBranchCheckedOut","messagePattern":"projectRoot is required for isBranchCheckedOut","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/common/utils/git-utils.ts","lineNumber":412,"sourceCode":"\t\t\t});\n\t\t}\n\n\t\treturn worktrees;\n\t} catch (error) {\n\t\treturn [];\n\t}\n}\n\n/**\n * Check if a branch is checked out in any worktree\n * Returns the worktree path if found, null otherwise\n */\nexport async function isBranchCheckedOut(\n\tprojectRoot: string,\n\tbranchName: string\n): Promise<string | null> {\n\tif (!projectRoot) {\n\t\tthrow new Error('projectRoot is required for isBranchCheckedOut');\n\t}\n\tif (!branchName) {\n\t\tthrow new Error('branchName is required for isBranchCheckedOut');\n\t}\n\n\tconst worktrees = await getWorktrees(projectRoot);\n\tconst worktree = worktrees.find((wt) => wt.branch === branchName);\n\treturn worktree ? worktree.path : null;\n}\n","sourceCodeStart":394,"sourceCodeEnd":422,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/common/utils/git-utils.ts#L394-L422","documentation":"isBranchCheckedOut() returns the worktree path where a branch is checked out, or null. It first validates that projectRoot was supplied, since it delegates to getWorktrees(projectRoot) which needs a cwd for the git command.","triggerScenarios":"Calling isBranchCheckedOut('', 'main') or with undefined/null projectRoot — e.g. a git workflow step running before the project root was resolved.","commonSituations":"Automation scripts reading an empty env var or config key for the repo path; tests forgetting to seed the project root; callers mixing up argument order and passing the branch name first.","solutions":["Pass a non-empty project root as the first argument","Resolve the root via findProjectRoot() or process.cwd() before calling","Fix argument order if the branch name was accidentally passed as the first parameter"],"exampleFix":"// before\nawait isBranchCheckedOut(branchName, projectRoot); // wrong order / empty root\n// after\nawait isBranchCheckedOut(projectRoot, branchName);","handlingStrategy":"validation","validationCode":"if (!projectRoot) throw new Error('projectRoot is required');\nif (!branchName) throw new Error('branchName is required');","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  const wtPath = await isBranchCheckedOut(root, branch);\n} catch (err) {\n  if (err.message.includes('projectRoot is required')) {\n    throw new Error('Config error: project root not resolved');\n  }\n  throw err;\n}","preventionTips":["Validate both arguments before every git-utils call","Keep argument order consistent (root first, branch second)","Fail fast at config-load time if the repo path is missing"],"tags":["git","argument-validation","branches"],"backgroundTag":"missing-required-argument","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}