{"record":{"id":"da5bcea4d9712eb7","repo":"yamadashy/repomix","slug":"failed-to-get-git-logs-error-as-error-message","errorCode":null,"errorMessage":"Failed to get git logs: ${(error as Error).message}","messagePattern":"Failed to get git logs: (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/core/git/gitLogHandle.ts","lineNumber":109,"sourceCode":"  let gitLogResult: GitLogResult | undefined;\n\n  if (config.output.git?.includeLogs) {\n    try {\n      // Use the first directory as the git repository root\n      // Usually this would be the root of the project\n      const gitRoot = rootDirs[0] || config.cwd;\n      const maxCommits = config.output.git?.includeLogsCount || 50;\n      const logContent = await deps.getGitLog(gitRoot, maxCommits);\n\n      // Parse the raw log content into structured commits\n      const commits = parseGitLog(logContent);\n\n      gitLogResult = {\n        logContent,\n        commits,\n      };\n    } catch (error) {\n      throw new RepomixError(`Failed to get git logs: ${(error as Error).message}`, { cause: error });\n    }\n  }\n\n  return gitLogResult;\n};\n","sourceCodeStart":91,"sourceCodeEnd":115,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/git/gitLogHandle.ts#L91-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run inside a valid git repository, or `git init && git commit` if history is intentionally absent.","Install/verify git: `git --version` must succeed in the same environment.","Inspect the appended message and error.cause for the exact git failure and fix it (e.g. repair history, clear index.lock)."],"exampleFix":"// before (folder without .git)\nnpx repomix ./exported-folder   // Failed to get git logs\n// after\ncd exported-folder && git init && git add -A && git commit -m init\nnpx repomix .","handlingStrategy":"try-catch","validationCode":"import { execFileSync } from 'node:child_process';\nconst hasGitHistory = (dir: string) => {\n  try { execFileSync('git', ['-C', dir, 'log', '-1'], { stdio: 'ignore' }); return true; }\n  catch { return false; }\n};\nif (!hasGitHistory(targetDir)) throw new Error('No git history available; git logs cannot be collected.');","typeGuard":"const isGitLogError = (e: unknown): e is RepomixError =>\n  e instanceof RepomixError && e.message.startsWith('Failed to get git logs:');","tryCatchPattern":"try {\n  const logs = await getGitLogs(...);\n} catch (error) {\n  if (isGitLogError(error)) {\n    console.warn('Git log collection skipped:', error.message, 'cause:', error.cause);\n  } else throw error;\n}","preventionTips":["Run against directories that contain a .git folder with at least one commit.","Install git in CI/Docker images used for packing.","Check error.cause for the exact git stderr when diagnosing.","Skip log-dependent options when processing archives or exports without history."],"tags":["git","subprocess","log"],"backgroundTag":"git-command-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}