eyaltoledano/claude-task-master · 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. Because an empty root is invalid, the function throws this error before invoking git. It is a fail-fast argument validation identical in style to the other git-utils guards.

Solutions

  1. Provide the repository path explicitly: getRemoteBranches('/path/to/project')
  2. Fall back to process.cwd() at the call site when root is unknown
  3. Repair config resolution so projectRoot is always set before git utilities are used
  4. Check CI environment variables for the workspace path being empty

Example fix

// before
await getRemoteBranches(ciConfig.root); // ciConfig.root was ''
// after
await getRemoteBranches(ciConfig.root || process.env.GITHUB_WORKSPACE || process.cwd());
Defensive patterns

Strategy: validation

Validate before calling

if (!projectRoot || typeof projectRoot !== 'string') {
  throw new Error('getRemoteBranches requires a non-empty projectRoot');
}
// remote listing also needs remotes; verify after the root check:
const remotes = await execAsync('git remote', { cwd: projectRoot });

Type guard

function isProjectRoot(v: unknown): v is string {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  const remoteBranches = await getRemoteBranches(projectRoot);
} catch (err) {
  if (err instanceof Error && err.message.includes('getRemoteBranches')) {
    console.error('projectRoot not provided; skipping remote branch lookup.');
    return [];
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling getRemoteBranches(undefined) or '' — usually projectRoot came from an unset config value; also triggered indirectly via the remoteBranches wrapper.

Common situations: CI jobs where the checkout directory variable is empty; scripts executed outside the project directory with no root argument; refactors that dropped the default project-root argument.

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

Appendix: source

Thrown at packages/tm-core/src/common/utils/git-utils.ts:124

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

/**
 * Get list of all remote branches
 */
export async function getRemoteBranches(
	projectRoot: string
): Promise<string[]> {
	if (!projectRoot) {
		throw new Error('projectRoot is required for getRemoteBranches');
	}

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

View on GitHub (pinned to c0c98d367c)