eyaltoledano/claude-task-master · error · Error
projectRoot is required for isOnDefaultBranch
Error message
projectRoot is required for isOnDefaultBranch
What it means
isOnDefaultBranch() in git-utils.js requires an explicit projectRoot directory argument to run git commands against. The function throws immediately when the argument is missing, null, or empty because git operations need a working directory to resolve the current and default branches. This is a defensive guard ensuring callers don't silently query the wrong repository.
Source
Thrown at scripts/modules/utils/git-utils.js:264
for (const defaultName of commonDefaults) {
if (branches.includes(defaultName)) {
return defaultName;
}
}
return null;
}
}
/**
* Check if we're currently on the default branch
* @param {string} projectRoot - Directory to check (required)
* @returns {Promise<boolean>} True if on default branch
*/
async function isOnDefaultBranch(projectRoot) {
if (!projectRoot) {
throw new Error('projectRoot is required for isOnDefaultBranch');
}
try {
const currentBranch = await getCurrentBranch(projectRoot);
const defaultBranch = await getDefaultBranch(projectRoot);
return currentBranch && defaultBranch && currentBranch === defaultBranch;
} catch (error) {
return false;
}
}
/**
* Check and automatically switch tags based on git branch if enabled
* This runs automatically during task operations, similar to migration
* @param {string} projectRoot - Project root directory (required)
* @param {string} tasksPath - Path to tasks.json file
* @returns {Promise<void>}
*/View on GitHub (pinned to c0c98d367c)
Solutions
- Pass a resolved absolute projectRoot string as the first argument
- Resolve the root via findProjectRoot(process.cwd()) or equivalent before calling
- Ensure the calling code path always has a valid projectRoot (validate upstream)
Example fix
// before const onDefault = await isOnDefaultBranch(); // after const projectRoot = findProjectRoot(process.cwd()); const onDefault = await isOnDefaultBranch(projectRoot);
Defensive patterns
Strategy: validation
Validate before calling
if (!projectRoot || typeof projectRoot !== 'string') throw new Error('projectRoot must be a non-empty string before calling isOnDefaultBranch'); Type guard
function hasProjectRoot(root) { return typeof root === 'string' && root.length > 0; } Try / catch
try {
const onDefault = await isOnDefaultBranch(projectRoot);
} catch (err) {
if (err.message.includes('projectRoot is required')) {
projectRoot = findProjectRoot(process.cwd());
} else throw err;
} Prevention
- Always resolve projectRoot early in your command flow and pass it explicitly
- Wrap git-utils calls in a helper that resolves root from cwd if missing
When it happens
Trigger: Calling isOnDefaultBranch() with no argument, undefined, null, or an empty string as the projectRoot parameter.
Common situations: Refactoring callers that dropped the projectRoot argument; calling the utility from code that hasn't resolved the project root yet; passing a config object's missing projectRoot field.
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
- projectRoot is required for checkAndAutoSwitchGitTag
- 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/df94f7d962bcd12c.
Report an issue: GitHub.