GitoxideLabs/gitoxide · error

could not inspect a stash reference before rebasing

Error message

could not inspect a stash reference before rebasing: {err}

What it means

Before rewriting edits, `rewrite_edits` in gix-tix's stash module scans all references to find stash-associated commits. If iterating references yields an Err for any single ref, it returns "could not inspect a stash reference before rebasing: {err}" instead of skipping, to avoid silently dropping stash state during a rebase.

Solutions

  1. Run `git fsck` to locate the broken reference, then repair or delete it
  2. Delete stale stash refs (refs/stash, refs/tix/...) that point to missing objects
  3. Re-run the rebase after ref repair
Defensive patterns

Strategy: validation

Validate before calling

// verify all refs resolve before a stash-aware rebase
for r in repo.references()?.all()? {
    let r = r.map_err(|e| anyhow::anyhow!("stale ref: {e}"))?;
    let _ = r.try_id()?;
}

Try / catch

match rewrite_edits(...) {
    Err(e) if e.to_string().contains("stash reference") => {
        eprintln!("repair refs (git fsck) before rebasing");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Running a tix rebase/rewrite when `repo.references()?.all()?` returns an error for some reference — dangling oid after gc, corrupt ref entry, or unreadable ref storage.

Common situations: Repositories with pruned objects still referenced by refs; damaged packed-refs; interrupted git operations leaving inconsistent refs.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/b2aac8bc02206459. Report an issue: GitHub.

Appendix: source

Thrown at gix-tix/src/edit/stash.rs:57

}

pub(super) struct RewriteEdits {
    pub forward: Vec<RefEdit>,
    pub rollback: Vec<RefEdit>,
}

pub(super) fn rewrite_edits(
    repo: &gix::Repository,
    rewritten: &HashMap<ObjectId, Option<ObjectId>>,
    removed: &HashSet<ObjectId>,
) -> Result<RewriteEdits> {
    let mut moves = Vec::new();
    let mut destinations = HashMap::<ObjectId, ObjectId>::new();
    for reference in repo.references()?.all()? {
        let reference = match reference {
            Ok(reference) => reference,
            Err(err) => {
                return Err(anyhow::anyhow!(
                    "could not inspect a stash reference before rebasing: {err}"
                ));
            }
        };
        let old = match associated_commit(reference.name().as_bstr()) {
            Ok(Some(id)) => id,
            Ok(None) => continue,
            Err(err) => {
                tracing::warn!(name = %reference.name(), error = %err, "ignored malformed tix stash reference");
                continue;
            }
        };
        let Some(new) = rewritten.get(&old).copied() else {
            continue;
        };
        if removed.contains(&old) {
            anyhow::bail!("cannot drop stashed commit {}", old.to_hex_with_len(7));
        }

View on GitHub (pinned to e73179060b)