moghtech/komodo · error · anyhow::Error

Failed to get short hash |

Error message

Failed to get short hash | {}

What it means

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.

Solutions

  1. Inspect the stderr embedded in the message to see the actual git failure
  2. Ensure the target directory is a git repository with at least one commit (git init && git commit)
  3. Run `git rev-parse --short HEAD` manually in that directory to reproduce the git error
  4. Fix repository state (e.g. safe.directory / permissions) per the stderr, or use init_folder_as_repo to initialize it first
Defensive patterns

Strategy: try-catch

Validate before calling

fn has_commits(dir: &Path) -> bool {
  std::process::Command::new("git").current_dir(dir)
    .args(["rev-parse", "--verify", "HEAD"]).output()
    .map(|o| o.status.success()).unwrap_or(false)
}

Try / catch

match get_commit_hash_log(dir).await {
  Err(e) if e.to_string().starts_with("Failed to get short hash") => {
    log::warn!("repo has no hash: {}", e); None
  }
  other => other.ok(),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of moghtech/komodo@780ac68b99 (2026-09-08). Data as JSON: /api/errors/09c88f0c2b8388ee. Report an issue: GitHub.

Appendix: source

Thrown at lib/git/src/lib.rs:40

  pull::pull,
  pull_or_clone::pull_or_clone,
};

pub async fn get_commit_hash_info(
  repo_dir: &Path,
) -> anyhow::Result<LatestCommit> {
  check_installed().await?;
  let hash = run_standard_command(
    "git rev-parse --short HEAD",
    CommandOptions::default()
      .path(repo_dir)
      .timeout(Duration::from_secs(2)),
  )
  .await;
  let hash = if hash.status.success() {
    hash.stdout.trim().to_string()
  } else {
    return Err(anyhow!(
      "Failed to get short hash | {}",
      hash.stderr
    ));
  };
  let message = run_standard_command(
    "git log -1 --pretty=%B",
    CommandOptions::default()
      .path(repo_dir)
      .timeout(Duration::from_secs(2)),
  )
  .await;
  let message = if message.status.success() {
    message.stdout.trim().to_string()
  } else {
    return Err(anyhow!(
      "Failed to get commit message | {}",
      message.stderr
    ));

View on GitHub (pinned to 780ac68b99)