{"record":{"id":"a7fafb76c93f7bed","repo":"GitoxideLabs/gitoxide","slug":"bug-invalid-state-we-never-discard-only-our-file","errorCode":null,"errorMessage":"BUG: Invalid state: we never discard only our file, always both.","messagePattern":"BUG: Invalid state: we never discard only our file, always both\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-ref/src/store/file/log/iter.rs","lineNumber":240,"sourceCode":"                            .into()));\n                        }\n                        let n = (last_read_pos - npos) as usize;\n                        self.buf.copy_within(0..end, n);\n                        if let Err(err) = read.seek(std::io::SeekFrom::Start(npos)) {\n                            return Some(Err(err.into()));\n                        }\n                        if let Err(err) = read.read_exact(&mut self.buf[..n]) {\n                            return Some(Err(err.into()));\n                        }\n                        self.read_and_pos = Some((read, npos));\n                        self.last_nl_pos = Some(n + end);\n                        self.next()\n                    }\n                }\n            },\n            // depleted\n            (None, None) => None,\n            (Some(_), None) => unreachable!(\"BUG: Invalid state: we never discard only our file, always both.\"),\n        }\n    }\n}\n","sourceCodeStart":222,"sourceCodeEnd":244,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-ref/src/store/file/log/iter.rs#L222-L244","documentation":"An `unreachable!()` panic in gix-ref's packed+loose reflog iterator `next()` (`store/file/log/iter`). The iterator walks two sources (own-file and packed reflog) in lockstep and asserts it never reaches the state `(Some(_), None)` — having only the own-file entry while the packed side is exhausted — because both files are discarded together during iteration. The panic fires if that invariant breaks.","triggerScenarios":"Iterating a reflog (e.g. `repo.reflog()` or reflog-based history traversal) over a repository where the loose reflog file and the packed-refs reflog are out of sync in a way the iterator didn't anticipate — e.g. manually deleted or partially compacted files under `.git/logs/`, or a gix-ref iteration bug.","commonSituations":"Repositories maintained by mixed tooling (git gc/repack interleaved with gix, manual cleanup of `.git/logs`), corrupted or hand-edited reflog storage, or fresh gix versions with iterator regressions.","solutions":["Restore reflog consistency: run `git reflog` / `git fsck` with real git, or delete the affected reflog files (`rm -rf .git/logs/<ref>`) so they can be rebuilt","Re-clone or re-pack the repository if reflog history is disposable (`git clone --mirror` + fresh fetch)","Upgrade gix / gix-ref and retry; report the repository layout that triggered it upstream"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn reflog_files_consistent(git_dir: &Path, ref_name: &str) -> bool {\n    let loose = git_dir.join(\"logs\").join(ref_name);\n    loose.exists() // if loose reflog exists, packed side is derived automatically; manual deletion of one side is the risk\n}","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| iter.collect::<Vec<_>>())\n    .map_err(|_| \"reflog iteration hit inconsistent storage; rebuild reflogs\")?","preventionTips":["Do not manually delete individual reflog files under .git/logs; remove whole reflogs instead","Run `git fsck` after tooling that rewrites ref storage (gc, repack, migrations)","Avoid interleaving gix and git ref-rewriting operations on the same repo mid-flight","Keep gix-ref updated; iterator state-machine bugs are fixed in releases"],"tags":["rust","panic","reflog","refs","iteration"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}