eyaltoledano/claude-task-master · error

projectRoot is required for getCurrentBranch

Error message

projectRoot is required for getCurrentBranch

What it means

getCurrentBranch() runs 'git rev-parse --abbrev-ref HEAD' in projectRoot to read the current branch name. It throws when projectRoot is falsy, since the git command needs a working directory; without a repo it would otherwise return null.

Source

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

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

	try {
		await execAsync('git rev-parse --git-dir', { cwd: projectRoot });
		return true;
	} catch (error) {
		return false;
	}
}

/**
 * Get the current git branch name
 * @param {string} projectRoot - Directory to check (required)
 * @returns {Promise<string|null>} Current branch name or null if not in git repo
 */
async function getCurrentBranch(projectRoot) {
	if (!projectRoot) {
		throw new Error('projectRoot is required for getCurrentBranch');
	}

	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) {

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Call with an explicit root: await getCurrentBranch(process.cwd())
  2. Resolve/validate projectRoot before the call and skip git features if absent
  3. Fix the upstream caller that passes undefined
  4. Guard: if (!projectRoot) return null instead of calling

Example fix

// before
const branch = await getCurrentBranch();
// after
const branch = projectRoot ? await getCurrentBranch(projectRoot) : null;
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling getCurrentBranch() with no argument, or with an empty/undefined projectRoot variable propagated from failed root detection.

Common situations: Displaying the current branch in CLI output when the projectRoot was not resolved; invoking git-utils from a script where args were reordered; empty environment variable for the project 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/bc29bff5460fa87c. Report an issue: GitHub.