eyaltoledano/claude-task-master · error
projectRoot is required for isGitRepository
Error message
projectRoot is required for isGitRepository
What it means
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.
Source
Thrown at scripts/modules/utils/git-utils.js:22
* Uses raw git commands and gh CLI for operations
* MCP-friendly: All functions require projectRoot parameter
*/
import { exec, execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { promisify } from 'util';
const execAsync = promisify(exec);
/**
* Check if the specified directory is inside a git repository
* @param {string} projectRoot - Directory to check (required)
* @returns {Promise<boolean>} True if inside a git repository
*/
async function isGitRepository(projectRoot) {
if (!projectRoot) {
throw new Error('projectRoot is required for isGitRepository');
}
try {
await execAsync('git rev-parse --git-dir', { cwd: projectRoot });
return true;
} catch (error) {
return false;
}
}
/**
* Get the current git branch name
* @param {string} projectRoot - Directory to check (required)
* @returns {Promise<string|null>} Current branch name or null if not in git repo
*/
async function getCurrentBranch(projectRoot) {
if (!projectRoot) {
throw new Error('projectRoot is required for getCurrentBranch');View on GitHub (pinned to c0c98d367c)
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
Example fix
// before const inGit = await isGitRepository(projectRoot); // after const root = projectRoot || process.cwd(); const inGit = await isGitRepository(root);
Defensive patterns
Strategy: validation
Validate before calling
if (!projectRoot || typeof projectRoot !== 'string') {
throw new TypeError('isGitRepository requires a non-empty projectRoot path');
}
const inRepo = await isGitRepository(projectRoot); Type guard
function hasProjectRoot(p) {
return typeof p === 'string' && p.trim().length > 0;
} Try / catch
try {
const inRepo = await isGitRepository(projectRoot);
} catch (err) {
if (err.message.includes('projectRoot is required')) {
console.error('No project root resolved; run inside a project or pass a path.');
return false;
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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 getCurrentBranch
- projectRoot is required for getLocalBranches
- projectRoot is required for getRemoteBranches
- projectRoot is required for getGitHubRepoInfo
- projectRoot is required for getGitRepositoryRoot
AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29).
Data as JSON: /api/errors/1f21839ba8abf613.
Report an issue: GitHub.