{"record":{"id":"1947611e19d58c89","repo":"eyaltoledano/claude-task-master","slug":"branchname-is-required-for-isbranchcheckedout","errorCode":null,"errorMessage":"branchName is required for isBranchCheckedOut","messagePattern":"branchName is required for isBranchCheckedOut","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/tm-core/src/common/utils/git-utils.ts","lineNumber":415,"sourceCode":"\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":397,"sourceCodeEnd":422,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/packages/tm-core/src/common/utils/git-utils.ts#L397-L422","documentation":"isBranchCheckedOut() requires a branch name to search for among worktrees; if branchName is missing/empty it throws before querying worktrees. This prevents an ambiguous lookup that would never match any worktree.","triggerScenarios":"Calling isBranchCheckedOut(root, '') or (root, undefined) — commonly when the branch name comes from an unset env var, a parsed-but-empty CLI flag, or a variable that was never assigned.","commonSituations":"CI pipelines where the branch variable is only set on push events (not on tag builds); scripts reading git branch output that failed silently upstream.","solutions":["Pass the branch name to check: await isBranchCheckedOut(root, 'feature/x')","Derive the current branch first: await getCurrentBranch(root)","Fail fast upstream if the branch variable is empty"],"exampleFix":"// before\nconst path = await isBranchCheckedOut(root, process.env.BRANCH);\n// after\nconst branch = process.env.BRANCH || (await getCurrentBranch(root));\nif (!branch) throw new Error('No branch specified');\nconst path = await isBranchCheckedOut(root, branch);","handlingStrategy":"validation","validationCode":"if (!branchName || typeof branchName !== 'string') throw new Error('A branch name is required');\nconst branch = branchName || (await getCurrentBranch(projectRoot));","typeGuard":"function isBranchName(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0 && !v.includes(' ');\n}","tryCatchPattern":"try {\n  const path = await isBranchCheckedOut(root, branch);\n} catch (err) {\n  if (err.message.includes('branchName is required')) {\n    branch = await getCurrentBranch(root);\n    return isBranchCheckedOut(root, branch);\n  }\n  throw err;\n}","preventionTips":["Derive the branch from git (getCurrentBranch) instead of env vars when possible","Guard CI-only variables (BRANCH/GITHUB_HEAD_REF) with fallbacks","Log the branch value at call sites to catch empty strings early"],"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"}