eyaltoledano/claude-task-master · error · Error

projectRoot is required for getRemoteBranches

Error message

projectRoot is required for getRemoteBranches

What it means

getRemoteBranches() runs 'git branch -r --format="%(refname:short)"' with cwd=projectRoot to list remote-tracking branches. It throws when projectRoot is falsy because the git command requires a working directory.

Source

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

		);
		return stdout
			.trim()
			.split('\n')
			.filter((branch) => branch.length > 0)
			.map((branch) => branch.trim());
	} catch (error) {
		return [];
	}
}

/**
 * Get list of all remote branches
 * @param {string} projectRoot - Directory to check (required)
 * @returns {Promise<string[]>} Array of remote branch names (without remote prefix)
 */
async function getRemoteBranches(projectRoot) {
	if (!projectRoot) {
		throw new Error('projectRoot is required for getRemoteBranches');
	}

	try {
		const { stdout } = await execAsync(
			'git branch -r --format="%(refname:short)"',
			{ cwd: projectRoot }
		);
		return stdout
			.trim()
			.split('\n')
			.filter((branch) => branch.length > 0 && !branch.includes('HEAD'))
			.map((branch) => branch.replace(/^origin\//, '').trim());
	} catch (error) {
		return [];
	}
}

/**

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass an explicit root: await getRemoteBranches(process.cwd())
  2. Resolve projectRoot (findProjectRoot or config) before calling and fail with a clear message if absent
  3. Fix the destructuring/caller that drops the argument
  4. Guard: only call when projectRoot is truthy

Example fix

// before
const remotes = await getRemoteBranches(projectRoot);
// after
const root = projectRoot ?? findProjectRoot(process.cwd());
if (!root) throw new Error('Could not determine project root');
const remotes = await getRemoteBranches(root);
Defensive patterns

Strategy: validation

Validate before calling

if (!projectRoot) {
  throw new TypeError('getRemoteBranches requires a projectRoot');
}
const remotes = await getRemoteBranches(projectRoot);

Type guard

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

Try / catch

try {
  const remotes = await getRemoteBranches(projectRoot);
} catch (err) {
  if (err.message.includes('projectRoot is required')) {
    return [];
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling getRemoteBranches() with no argument or with null/undefined/'' projectRoot, e.g. when root auto-detection returned nothing upstream.

Common situations: Listing remote branches for PR/PRD workflows from a directory where projectRoot was never established; passing the wrong variable (undefined) due to destructuring; CI environments without the project path set.

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/8843366f82611cac. Report an issue: GitHub.