{"record":{"id":"09c88f0c2b8388ee","repo":"moghtech/komodo","slug":"failed-to-get-short-hash","errorCode":null,"errorMessage":"Failed to get short hash | {}","messagePattern":"Failed to get short hash \\| (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"lib/git/src/lib.rs","lineNumber":40,"sourceCode":"  pull::pull,\n  pull_or_clone::pull_or_clone,\n};\n\npub async fn get_commit_hash_info(\n  repo_dir: &Path,\n) -> anyhow::Result<LatestCommit> {\n  check_installed().await?;\n  let hash = run_standard_command(\n    \"git rev-parse --short HEAD\",\n    CommandOptions::default()\n      .path(repo_dir)\n      .timeout(Duration::from_secs(2)),\n  )\n  .await;\n  let hash = if hash.status.success() {\n    hash.stdout.trim().to_string()\n  } else {\n    return Err(anyhow!(\n      \"Failed to get short hash | {}\",\n      hash.stderr\n    ));\n  };\n  let message = run_standard_command(\n    \"git log -1 --pretty=%B\",\n    CommandOptions::default()\n      .path(repo_dir)\n      .timeout(Duration::from_secs(2)),\n  )\n  .await;\n  let message = if message.status.success() {\n    message.stdout.trim().to_string()\n  } else {\n    return Err(anyhow!(\n      \"Failed to get commit message | {}\",\n      message.stderr\n    ));","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/moghtech/komodo/blob/780ac68b992094a9fccd5fffb760e0c84fd3c3d1/lib/git/src/lib.rs#L22-L58","documentation":"get_commit_hash_info first runs `git rev-parse --short` (with a 2s timeout) to obtain the short commit hash; if that command exits non-zero it wraps the captured stderr into this anyhow error. It indicates git could not resolve a commit hash in the target repository, with the underlying git diagnostics embedded after the '|' separator.","triggerScenarios":"Calling get_commit_hash_info (via get_commit_hash_log) on a path that is not a git repository, a repository with no commits (unborn HEAD), or where the git subprocess fails or times out after 2 seconds.","commonSituations":"Pointing the library at a freshly created folder that hasn't been `git init`-ed or committed yet; the repo directory was deleted/moved; git operations blocked by ownership/safe.directory issues producing stderr.","solutions":["Inspect the stderr embedded in the message to see the actual git failure","Ensure the target directory is a git repository with at least one commit (git init && git commit)","Run `git rev-parse --short HEAD` manually in that directory to reproduce the git error","Fix repository state (e.g. safe.directory / permissions) per the stderr, or use init_folder_as_repo to initialize it first"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn has_commits(dir: &Path) -> bool {\n  std::process::Command::new(\"git\").current_dir(dir)\n    .args([\"rev-parse\", \"--verify\", \"HEAD\"]).output()\n    .map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match get_commit_hash_log(dir).await {\n  Err(e) if e.to_string().starts_with(\"Failed to get short hash\") => {\n    log::warn!(\"repo has no hash: {}\", e); None\n  }\n  other => other.ok(),\n}","preventionTips":["Ensure the directory is git-initialized and has at least one commit before querying","Run `git rev-parse --short HEAD` in CI as a preflight","Watch for the 2s subprocess timeout on slow/network filesystems"],"tags":["git","subprocess","commit-hash","repository-state"],"backgroundTag":"git-command-failed","analyzedSha":"780ac68b992094a9fccd5fffb760e0c84fd3c3d1","analyzedAt":"2026-09-08T10:02:44.861Z","contentChangedAt":"2026-09-08T10:02:44.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}