yamadashy/repomix · error · RepomixError

Failed to get git logs: ${(error as Error).message}

Error message

Failed to get git logs: ${(error as Error).message}

What it means

getGitLogs executes git log commands to build commit history output and, on any failure, re-throws as a RepomixError with this message, the underlying git error text appended, and the original error preserved as `cause`. Failures typically mean git could not run or the path is not a repository.

Source

Thrown at src/core/git/gitLogHandle.ts:109

  let gitLogResult: GitLogResult | undefined;

  if (config.output.git?.includeLogs) {
    try {
      // Use the first directory as the git repository root
      // Usually this would be the root of the project
      const gitRoot = rootDirs[0] || config.cwd;
      const maxCommits = config.output.git?.includeLogsCount || 50;
      const logContent = await deps.getGitLog(gitRoot, maxCommits);

      // Parse the raw log content into structured commits
      const commits = parseGitLog(logContent);

      gitLogResult = {
        logContent,
        commits,
      };
    } catch (error) {
      throw new RepomixError(`Failed to get git logs: ${(error as Error).message}`, { cause: error });
    }
  }

  return gitLogResult;
};

View on GitHub (pinned to f465ad9093)

Solutions

  1. Run inside a valid git repository, or `git init && git commit` if history is intentionally absent.
  2. Install/verify git: `git --version` must succeed in the same environment.
  3. Inspect the appended message and error.cause for the exact git failure and fix it (e.g. repair history, clear index.lock).

Example fix

// before (folder without .git)
npx repomix ./exported-folder   // Failed to get git logs
// after
cd exported-folder && git init && git add -A && git commit -m init
npx repomix .
Defensive patterns

Strategy: try-catch

Validate before calling

import { execFileSync } from 'node:child_process';
const hasGitHistory = (dir: string) => {
  try { execFileSync('git', ['-C', dir, 'log', '-1'], { stdio: 'ignore' }); return true; }
  catch { return false; }
};
if (!hasGitHistory(targetDir)) throw new Error('No git history available; git logs cannot be collected.');

Type guard

const isGitLogError = (e: unknown): e is RepomixError =>
  e instanceof RepomixError && e.message.startsWith('Failed to get git logs:');

Try / catch

try {
  const logs = await getGitLogs(...);
} catch (error) {
  if (isGitLogError(error)) {
    console.warn('Git log collection skipped:', error.message, 'cause:', error.cause);
  } else throw error;
}

Prevention

When it happens

Trigger: Calling getGitLogs (or the git-log processing path) when git is missing from PATH, the target directory has no .git, the directory is a bare/unusual repo, or the git log subprocess exits non-zero.

Common situations: Running on a copied folder without .git; minimal CI images without git installed; repos with zero commits or corrupted history; shallow clones with unusual configs.

Related errors


AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29). Data as JSON: /api/errors/da5bcea4d9712eb7. Report an issue: GitHub.