eyaltoledano/claude-task-master · error

projectRoot is required for getLocalBranches

Error message

projectRoot is required for getLocalBranches

What it means

getLocalBranches() runs 'git branch --format="%(refname:short)"' with cwd set to projectRoot to list local branches. It throws when projectRoot is falsy because the command must be executed inside the target repository.

Source

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

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

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

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

/**

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass an explicit path: await getLocalBranches(process.cwd())
  2. Verify you are inside a project/git repo before invoking and surface a clearer message otherwise
  3. Fix the caller that yields an empty projectRoot
  4. Guard the call site: if (!projectRoot) return []

Example fix

// before
const branches = await getLocalBranches();
// after
if (!projectRoot) throw new Error('Run this command inside a project directory');
const branches = await getLocalBranches(projectRoot);
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try {
  const branches = await getLocalBranches(projectRoot);
} catch (err) {
  if (err.message.includes('projectRoot is required')) {
    console.error('Run this command inside a project directory.');
    return [];
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling getLocalBranches() without arguments or with an empty string/null projectRoot, usually from a caller (e.g. the 'branches' command) whose root detection failed.

Common situations: Running the branches command outside a project directory; projectRoot passed as undefined after a failed findProjectRoot(); tests calling the helper without a fixture repo path.

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