Byron / gitoxide

An idiomatic, lean, fast & safe pure Rust implementation of Git
Apache License 2.0
8.84k stars 301 forks source link

Panic when parsing `HEAD:README` in a repo with invalid HEAD. #1508

Closed axelkar closed 1 month ago

axelkar commented 1 month ago

Current behavior 😯

thread 'tokio-runtime-worker' panicked at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/revision/spec/parse/error.rs:108:9:
assertion failed: !errors.is_empty()
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: gix::revision::spec::parse::error::<impl gix::revision::spec::parse::types::Error>::from_errors
             at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/revision/spec/parse/error.rs:108:9
   4: gix::revision::spec::parse::delegate::<impl gix::revision::spec::parse::Delegate>::into_err
             at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/revision/spec/parse/delegate/mod.rs:44:9
   5: gix::revision::spec::parse::<impl gix::revision::Spec>::_from_bstr_inner_generated_by_gix_macro_momo
             at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/revision/spec/parse/mod.rs:41:48
   6: gix::revision::spec::parse::<impl gix::revision::Spec>::from_bstr
             at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/revision/spec/parse/mod.rs:37:5
   7: gix::repository::revision::<impl gix::types::Repository>::_rev_parse_inner_generated_by_gix_macro_momo
             at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/repository/revision.rs:16:9
   8: gix::repository::revision::<impl gix::types::Repository>::rev_parse
             at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/repository/revision.rs:14:5
   9: gix::repository::revision::<impl gix::types::Repository>::rev_parse_single
             at /home/axel/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/gix-0.64.0/src/repository/revision.rs:33:9
  10: rgitweb::repo_home::{{closure}}
             at ./src/main.rs:354:13
*super verbose tokio, axum and tower stack trace*
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Expected behavior 🤔

It shouldn't panic.

Git behavior

Talks about nonexistent branch being empty. Not sure about libgit2.

Steps to reproduce 🕹

let repo = gix::open("nixos_iced_aw.git").unwrap();
let _ = repo.rev_parse_single("HEAD:README");
// Doesn't get here

nixos_iced_aw.got is a bare repository whose HEAD points to the master branch, which has been deleted. Here's the repo: https://git.axka.fi/nixos_iced_aw.git. I'm not sure if cloning it will reproduce this, but you can make a bare repo with a commit and then point HEAD to something non-existent.

Cgit deals with it, Git says fatal: your current branch 'master' does not have any commits yet and gix panics.

Byron commented 1 month ago

Thank you for reporting! I could reproduce the issue and am working on a fix.

Byron commented 1 month ago

When released, gix will instead say: Could not peel 'HEAD' to obtain its target.