Skip to content

Commit

Permalink
fix(): error context for git_fetch refspec not found
Browse files Browse the repository at this point in the history
  • Loading branch information
dacianpascu06 committed Nov 10, 2024
1 parent d8cb5fb commit a91d980
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,13 @@ pub fn fetch(
continue;
}
}
if matches!(err.class(), ErrorClass::Net) && err.code() == git2::ErrorCode::Eof {
let revspec_id: String = refspecs
.iter()
.map(|s| s.split(':').next().unwrap_or("").to_string())
.collect();
return Err(anyhow!("refspec {revspec_id} not found on {remote_url}"));
}

return Err(err.into());
}
Expand Down Expand Up @@ -1221,9 +1228,21 @@ fn fetch_with_cli(
.env_remove("GIT_OBJECT_DIRECTORY")
.env_remove("GIT_ALTERNATE_OBJECT_DIRECTORIES")
.cwd(repo.path());

gctx.shell()
.verbose(|s| s.status("Running", &cmd.to_string()))?;
cmd.exec()?;

let revspec_id: String = refspecs
.iter()
.map(|s| s.split(':').next().unwrap_or("").to_string())
.collect();

cmd.exec().with_context(|| {
format!(
"Failed to fetch via Github fast path \nrevspec {:?} not found",
revspec_id
)
})?;
Ok(())
}

Expand Down
84 changes: 84 additions & 0 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,90 @@ src/lib.rs
.run();
}

#[cargo_test(public_network_test)]
fn github_fastpath_error_message() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
[dependencies]
bitflags = { git = "https://github.com/rust-lang/bitflags.git", rev="11111b376b93484341c68fbca3ca110ae5cd2790" }
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("fetch")
.env("CARGO_NET_GIT_FETCH_WITH_CLI", "true")
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] git repository `https://github.com/rust-lang/bitflags.git`
fatal: remote [ERROR] upload-pack: not our ref 11111b376b93484341c68fbca3ca110ae5cd2790
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
Caused by:
failed to load source for dependency `bitflags`
Caused by:
Unable to update https://github.com/rust-lang/bitflags.git?rev=11111b376b93484341c68fbca3ca110ae5cd2790
Caused by:
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
Caused by:
Failed to fetch via Github fast path
revspec "+11111b376b93484341c68fbca3ca110ae5cd2790" not found
Caused by:
process didn't exit successfully: `git fetch --no-tags --force --update-head-ok 'https://github.com/rust-lang/bitflags.git' '+11111b376b93484341c68fbca3ca110ae5cd2790:refs/commit/11111b376b93484341c68fbca3ca110ae5cd2790'` ([EXIT_STATUS]: 128)
"#]])
.run();
}

#[cargo_test]
fn git_fetch_cli_false() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"
[dependencies]
bitflags = { git = "https://github.com/rust-lang/bitflags.git", rev="11111b376b93484341c68fbca3ca110ae5cd2790" }
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("fetch")
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] git repository `https://github.com/rust-lang/bitflags.git`
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
Caused by:
failed to load source for dependency `bitflags`
Caused by:
Unable to update https://github.com/rust-lang/bitflags.git?rev=11111b376b93484341c68fbca3ca110ae5cd2790
Caused by:
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
Caused by:
refspec +11111b376b93484341c68fbca3ca110ae5cd2790 not found on https://github.com/rust-lang/bitflags.git
"#]])
.run();
}

#[cargo_test]
fn git_worktree_with_bare_original_repo() {
let project = project().build();
Expand Down

0 comments on commit a91d980

Please sign in to comment.