eyaltoledano/claude-task-master · error
projectRoot is required for isBranchCheckedOut
Error message
projectRoot is required for isBranchCheckedOut
What it means
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.
Source
Thrown at packages/tm-core/src/common/utils/git-utils.ts:412
});
}
return worktrees;
} catch (error) {
return [];
}
}
/**
* Check if a branch is checked out in any worktree
* Returns the worktree path if found, null otherwise
*/
export async function isBranchCheckedOut(
projectRoot: string,
branchName: string
): Promise<string | null> {
if (!projectRoot) {
throw new Error('projectRoot is required for isBranchCheckedOut');
}
if (!branchName) {
throw new Error('branchName is required for isBranchCheckedOut');
}
const worktrees = await getWorktrees(projectRoot);
const worktree = worktrees.find((wt) => wt.branch === branchName);
return worktree ? worktree.path : null;
}
View on GitHub (pinned to c0c98d367c)
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
Example fix
// before await isBranchCheckedOut(branchName, projectRoot); // wrong order / empty root // after await isBranchCheckedOut(projectRoot, branchName);
Defensive patterns
Strategy: validation
Validate before calling
if (!projectRoot) throw new Error('projectRoot is required');
if (!branchName) throw new Error('branchName is required'); Type guard
function isNonEmptyString(v: unknown): v is string {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
const wtPath = await isBranchCheckedOut(root, branch);
} catch (err) {
if (err.message.includes('projectRoot is required')) {
throw new Error('Config error: project root not resolved');
}
throw err;
} Prevention
- 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
When it happens
Trigger: Calling isBranchCheckedOut('', 'main') or with undefined/null projectRoot — e.g. a git workflow step running before the project root was resolved.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- branchName is required for isBranchCheckedOut
- projectRoot is required for isGitRepository
- projectRoot is required for getCurrentBranch
- projectRoot is required for getLocalBranches
- projectRoot is required for getRemoteBranches
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/99dbf2e43934db0a.
Report an issue: GitHub.