eyaltoledano/claude-task-master · error · Error

projectRoot is required for getGitRepositoryRoot

Error message

projectRoot is required for getGitRepositoryRoot

What it means

getGitRepositoryRoot() runs 'git rev-parse --show-toplevel' with cwd=projectRoot to find the repository root directory. It throws when projectRoot is falsy because the search needs a starting directory.

Source

Thrown at scripts/modules/utils/git-utils.js:186

	// Check if it's a reserved branch name that shouldn't become tags
	const reservedBranches = ['main', 'master', 'develop', 'dev', 'HEAD'];
	if (reservedBranches.includes(branchName.toLowerCase())) {
		return false;
	}

	// Check if sanitized name would be meaningful
	const sanitized = sanitizeBranchNameForTag(branchName);
	return sanitized.length > 0 && sanitized !== 'unknown-branch';
}

/**
 * Get git repository root directory
 * @param {string} projectRoot - Directory to start search from (required)
 * @returns {Promise<string|null>} Git repository root path or null
 */
async function getGitRepositoryRoot(projectRoot) {
	if (!projectRoot) {
		throw new Error('projectRoot is required for getGitRepositoryRoot');
	}

	try {
		const { stdout } = await execAsync('git rev-parse --show-toplevel', {
			cwd: projectRoot
		});
		return stdout.trim();
	} catch (error) {
		return null;
	}
}

/**
 * Check if specified directory is the git repository root
 * @param {string} projectRoot - Directory to check (required)
 * @returns {Promise<boolean>} True if directory is git root
 */
async function isGitRepositoryRoot(projectRoot) {

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass a starting directory: await getGitRepositoryRoot(process.cwd())
  2. Resolve projectRoot first and handle null before calling
  3. Fix the caller that passes undefined
  4. Guard: return null when projectRoot is absent instead of calling

Example fix

// before
const root = await getGitRepositoryRoot(projectRoot);
// after
const start = projectRoot || process.cwd();
const root = await getGitRepositoryRoot(start);
Defensive patterns

Strategy: validation

Validate before calling

if (!projectRoot) {
  throw new TypeError('getGitRepositoryRoot requires a starting directory');
}
const gitRoot = await getGitRepositoryRoot(projectRoot);

Type guard

function hasProjectRoot(p) {
  return typeof p === 'string' && p.trim().length > 0;
}

Try / catch

try {
  const gitRoot = await getGitRepositoryRoot(projectRoot);
} catch (err) {
  if (err.message.includes('projectRoot is required')) {
    return null;
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling getGitRepositoryRoot() without arguments or with an empty/undefined projectRoot, e.g. when resolving the repo root from an unresolved project root value.

Common situations: Locating the git root to store Task Master state; projectRoot was null because findProjectRoot() failed outside a project; passing an unassigned variable from an async init flow.

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


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/bc10d8ceeb3bbe99. Report an issue: GitHub.