Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git clone with depth 1 fails with code -20 #1084

Open
sj-robert opened this issue Sep 20, 2024 · 5 comments
Open

Git clone with depth 1 fails with code -20 #1084

sj-robert opened this issue Sep 20, 2024 · 5 comments
Labels
upstream An upstream issue with libgit2

Comments

@sj-robert
Copy link

Hi,

I have the following implementation:

    fn new(
        directory: TempDir,
        ssh_key: &'static std::path::Path,
        git_url: &'static str,
    ) -> Result<GitRepo<Master>, Box<dyn Error>> {
        tracing::info!("creating new repository from url {git_url}");
        let callbacks = GitRepo::<New>::callbacks(ssh_key);

        let mut fo = git2::FetchOptions::new();
        fo.depth(1);
        fo.remote_callbacks(callbacks);

        let mut builder = git2::build::RepoBuilder::new();
        builder.fetch_options(fo);

        // Clone the project.
        let repository = builder.clone(git_url, Path::new(directory.path()))?;

        // We need to do some extra juggling for the first action in the chain
        let next = Rc::new(New {});
        let repo = GitRepo {
            git_url,
            branch_name: "master".into(),
            directory,
            history: vec![next.clone()],
            state: next,
            change_state: ChangeState::Clean,
            ssh_key,
        };

        Ok(repo.next(Master {
            repository: Rc::new(repository),
        }))
    }

callbacks(ssh_key) looks like this:

    fn callbacks(ssh_key: &std::path::Path) -> RemoteCallbacks<'_> {
        let mut callbacks = RemoteCallbacks::new();
        callbacks.credentials(|_url, username_from_url, _allowed_types| {
            Cred::ssh_key(
                username_from_url.ok_or_else(|| git2::Error::from_str("no username from url"))?,
                None,
                ssh_key,
                None,
            )
        });
        callbacks
    }

This fails with an error that I cannot understand:

called `Result::unwrap()` on an `Err` value: Error { code: -20, klass: 23, message: "fatal: git upload-pack: expected SHA1 list, got 'want 5838d8cfd803c85c8f7534cb6d7108284c3f52f8 multi_ack_detailed side-band-64k include-tag thin-pack ofs-delta shallow '\n38d8cfd803c85c8f7534cb6d7108284c3f52f80000" }
stack backtrace:
   0:     0x6440510e2c05 - std::backtrace_rs::backtrace::libunwind::trace::h649ab3318d3445c5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x6440510e2c05 - std::backtrace_rs::backtrace::trace_unsynchronized::hf4bb60c3387150c3
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x6440510e2c05 - std::sys::backtrace::_print_fmt::hd9186c800e44bd00
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:65:5
   3:     0x6440510e2c05 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1b9dad2a88e955ff
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:40:26
   4:     0x64405110ed7b - core::fmt::rt::Argument::fmt::h351a7824f737a6a0
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/rt.rs:173:76
   5:     0x64405110ed7b - core::fmt::write::h4b5a1270214bc4a7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/mod.rs:1182:21
   6:     0x6440510df4ff - std::io::Write::write_fmt::hd04af345a50c312d
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/io/mod.rs:1827:15
   7:     0x6440510e3f01 - std::sys::backtrace::BacktraceLock::print::h68d41b51481bce5c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:43:9
   8:     0x6440510e3f01 - std::panicking::default_hook::{{closure}}::h96ab15e9936be7ed
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:269:22
   9:     0x6440510e3bdc - std::panicking::default_hook::h3cacb9c27561ad33
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:296:9
  10:     0x6440510e45d1 - std::panicking::rust_panic_with_hook::hfe205f6954b2c97b
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:800:13
  11:     0x6440510e4437 - std::panicking::begin_panic_handler::{{closure}}::h6cb44b3a50f28c44
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:674:13
  12:     0x6440510e30c9 - std::sys::backtrace::__rust_end_short_backtrace::hf1c1f2a92799bb0e
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:168:18
  13:     0x6440510e40c4 - rust_begin_unwind
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
  14:     0x64405110cc03 - core::panicking::panic_fmt::h3d8fc78294164da7
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:74:14
  15:     0x64405110d1b6 - core::result::unwrap_failed::hfa79a499befff387
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/result.rs:1679:5
  16:     0x64405098a26c - core::result::Result<T,E>::unwrap::h2424667e005c4eed
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/result.rs:1102:23
  17:     0x64405098a26c - rust_project::commands::command::generate::h8a2cde831a67b31f
                               at /home/usr/work/rust_project/src/commands/command.rs:52:26
  18:     0x6440509b1656 - rust_project::main::h928420af63cfcd85
                               at /home/usr/work/rust_project/src/main.rs:41:38
  19:     0x6440509809eb - core::ops::function::FnOnce::call_once::h43100a012b707c39
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250:5
  20:     0x644050990fae - std::sys::backtrace::__rust_begin_short_backtrace::hdc6958d1e0fa5652
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:152:18
  21:     0x6440509977a1 - std::rt::lang_start::{{closure}}::he013aeb9b95039af
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/rt.rs:162:18
  22:     0x6440510d6960 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h2feec6363bd28ad6
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:284:13
  23:     0x6440510d6960 - std::panicking::try::do_call::h71b24ad3a8e797d5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  24:     0x6440510d6960 - std::panicking::try::h8412d1bfb4bcbcc1
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  25:     0x6440510d6960 - std::panic::catch_unwind::h2053d3ee5bd8db53
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  26:     0x6440510d6960 - std::rt::lang_start_internal::{{closure}}::h82eb98fe4f8e75b8
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/rt.rs:141:48
  27:     0x6440510d6960 - std::panicking::try::do_call::h793dba66a0bbd3de
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557:40
  28:     0x6440510d6960 - std::panicking::try::he09b629b3ba06846
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521:19
  29:     0x6440510d6960 - std::panic::catch_unwind::h7964c913fc871155
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350:14
  30:     0x6440510d6960 - std::rt::lang_start_internal::h5e7c81cecd7f0954
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/rt.rs:141:20
  31:     0x64405099777a - std::rt::lang_start::hbbc730c624e4783e
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/rt.rs:161:17
  32:     0x6440509b20ce - main
  33:     0x7da3c4629d90 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  34:     0x7da3c4629e40 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:392:3
  35:     0x64405097b9a5 - _start
  36:                0x0 - <unknown>

Running it with depth(0) works, but is very slow due to the large history of the repo I'm cloning. If I can do more to help figure this out (if it's a bug in git2-rs) or if I should look elsewhere, just let me know :)

@weihanglo
Copy link
Member

Any change you are using custom transport?

There seems to be some similar issues in libgit2 libgit2/libgit2#5799 also using git2-rs, though I am not sure if that is actually the same thing.

@sj-robert
Copy link
Author

I don't know? Everything on the rust side is pretty standard, do you mean on the server-side for the git repo?

@ehuss
Copy link
Contributor

ehuss commented Sep 25, 2024

I filed an upstream issue at libgit2/libgit2#6889.

Can you please post a complete runnable example that demonstrates the problem that you are experiencing? I'm not quite getting the same error message that you are. For example:

use git2::*;
use std::path::Path;

fn main() {
    let mut callbacks = RemoteCallbacks::new();
    callbacks.credentials(|_url, username_from_url, _allowed_types| {
        Cred::ssh_key(
            username_from_url
                .ok_or_else(|| git2::Error::from_str("no username from url"))
                .unwrap(),
            None,
            Path::new("/Users/eric/.ssh/id_ed25519"),
            None,
        )
    });

    let mut fo = git2::FetchOptions::new();
    fo.depth(1);
    fo.remote_callbacks(callbacks);

    let mut builder = git2::build::RepoBuilder::new();
    builder.fetch_options(fo);

    builder
        .clone(
            "ssh://[email protected]/libgit2/libgit2.git",
            Path::new("asdf"),
        )
        .unwrap();
}

With that I get:

called `Result::unwrap()` on an `Err` value: Error { code: -20, klass: 12, message: "could not read from remote repository" }

@ehuss ehuss added the upstream An upstream issue with libgit2 label Sep 25, 2024
@HA55EHH
Copy link

HA55EHH commented Oct 4, 2024

With that I get:

called `Result::unwrap()` on an `Err` value: Error { code: -20, klass: 12, message: "could not read from remote repository" }

I get the same.

@sj-robert
Copy link
Author

Sorry for the late reply, I've been drowning in work-related issues. I'll try and get a minimal repro up next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream An upstream issue with libgit2
Projects
None yet
Development

No branches or pull requests

4 participants