eyaltoledano/claude-task-master · error · Error

projectRoot is required for getDefaultBranch

Error message

projectRoot is required for getDefaultBranch

What it means

getDefaultBranch() determines the repository's default branch, first via the gh CLI (getGitHubRepoInfo) and then via git remote HEAD fallback. It throws when projectRoot is falsy because all underlying git/gh commands need a working directory.

Source

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

		throw new Error('projectRoot is required for isGitRepositoryRoot');
	}

	try {
		const gitRoot = await getGitRepositoryRoot(projectRoot);
		return gitRoot && path.resolve(gitRoot) === path.resolve(projectRoot);
	} catch (error) {
		return false;
	}
}

/**
 * Get the default branch name for the repository
 * @param {string} projectRoot - Directory to check (required)
 * @returns {Promise<string|null>} Default branch name or null
 */
async function getDefaultBranch(projectRoot) {
	if (!projectRoot) {
		throw new Error('projectRoot is required for getDefaultBranch');
	}

	try {
		// Try to get from GitHub first (if gh CLI is available)
		if (await isGhCliAvailable(projectRoot)) {
			const repoInfo = await getGitHubRepoInfo(projectRoot);
			if (repoInfo && repoInfo.defaultBranchRef) {
				return repoInfo.defaultBranchRef.name;
			}
		}

		// Fallback to git remote info
		const { stdout } = await execAsync(
			'git symbolic-ref refs/remotes/origin/HEAD',
			{ cwd: projectRoot }
		);
		return stdout.replace('refs/remotes/origin/', '').trim();
	} catch (error) {

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Pass an explicit root: await getDefaultBranch(process.cwd())
  2. Resolve and validate projectRoot before calling
  3. Fix the caller that drops the argument
  4. Remember a null return (not a throw) means no default branch could be determined — handle both cases

Example fix

// before
const base = await getDefaultBranch();
// after
const base = projectRoot ? await getDefaultBranch(projectRoot) : 'main';
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try {
  const base = await getDefaultBranch(projectRoot);
} catch (err) {
  if (err.message.includes('projectRoot is required')) {
    return 'main';
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling getDefaultBranch() with a missing/null/'' projectRoot argument, often from the 'defaultBranch' helper whose caller did not resolve the root.

Common situations: Determining the base branch for PR creation; projectRoot undefined when running outside a project or in CI without the path configured; argument lost when refactoring the helper chain.

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