eyaltoledano/claude-task-master · error

not a git repository: ${this.projectPath}

Error message

not a git repository: ${this.projectPath}

What it means

Plain Error thrown by GitAdapter.getRepositoryRoot when `git rev-parse --show-toplevel` fails for the adapter's projectPath — normally because the directory is not inside a git working tree (also fired for other rev-parse failures, whose original message is discarded). The project path is interpolated into the message.

Source

Thrown at packages/tm-core/src/modules/git/adapters/git-adapter.ts:145

	}

	/**
	 * Gets the repository root path.
	 * Works even when called from a subdirectory.
	 *
	 * @returns {Promise<string>} Absolute path to repository root
	 * @throws {Error} If not in a git repository
	 *
	 * @example
	 * const root = await git.getRepositoryRoot();
	 * console.log(`Repository root: ${root}`);
	 */
	async getRepositoryRoot(): Promise<string> {
		try {
			const result = await this.git.revparse(['--show-toplevel']);
			return path.normalize(result.trim());
		} catch (error) {
			throw new Error(`not a git repository: ${this.projectPath}`);
		}
	}

	/**
	 * Validates the repository state.
	 * Checks for corruption and basic integrity.
	 *
	 * @returns {Promise<void>}
	 * @throws {Error} If repository is corrupted or invalid
	 *
	 * @example
	 * await git.validateRepository();
	 * console.log('Repository is valid');
	 */
	async validateRepository(): Promise<void> {
		// Check if it's a git repository
		const isRepo = await this.isGitRepository();
		if (!isRepo) {

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Run `git init` in projectPath if it should be a repository, or use the correct directory that already contains .git
  2. Verify with `git -C <projectPath> rev-parse --show-toplevel` to reproduce outside the library
  3. Call isGitRepository() first and branch your logic instead of relying on getRepositoryRoot throwing
  4. Check for a bare repo — --show-toplevel fails there; use git rev-parse --git-dir semantics instead
  5. Confirm no typo/case mismatch in projectPath and that .git still exists

Example fix

// before
const root = await git.getRepositoryRoot(); // throws if not a repo
// after
if (await git.isGitRepository()) {
  const root = await git.getRepositoryRoot();
} else {
  await git.ensureGitRepository(); // or init manually
  const root = await git.getRepositoryRoot();
}
Defensive patterns

Strategy: validation

Validate before calling

import { execFileSync } from 'child_process';
try {
  execFileSync('git', ['-C', projectPath, 'rev-parse', '--show-toplevel'], { stdio: 'pipe' });
} catch {
  throw new Error(`${projectPath} is not inside a git worktree`);
}

Type guard

function isGitWorktree(dir: string): boolean {
  try {
    execFileSync('git', ['-C', dir, 'rev-parse', '--is-inside-work-tree'], { stdio: 'pipe' });
    return true;
  } catch { return false; }
}

Try / catch

try {
  const root = await git.getRepositoryRoot();
} catch (e) {
  if (String(e.message).startsWith('not a git repository')) {
    await git.ensureGitRepository(); // init + commit scaffolding
    const root = await git.getRepositoryRoot();
  } else throw e;
}

Prevention

When it happens

Trigger: Calling getRepositoryRoot() when projectPath is outside any repository; the .git directory was deleted; the repo is bare (rev-parse --show-toplevel fails on bare repos); git init was never run; path case/typo points to a sibling non-repo directory.

Common situations: Freshly cloned-then-stripped projects; temp directories created without git init; CI checkouts using export without git metadata; running the tool one directory above/below where .git actually lives; detached/corrupt .git.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/8a609a75542e9a7b. Report an issue: GitHub.