Skip to content

Commit a91d980

Browse files
committed
fix(): error context for git_fetch refspec not found
1 parent d8cb5fb commit a91d980

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,13 @@ pub fn fetch(
11521152
continue;
11531153
}
11541154
}
1155+
if matches!(err.class(), ErrorClass::Net) && err.code() == git2::ErrorCode::Eof {
1156+
let revspec_id: String = refspecs
1157+
.iter()
1158+
.map(|s| s.split(':').next().unwrap_or("").to_string())
1159+
.collect();
1160+
return Err(anyhow!("refspec {revspec_id} not found on {remote_url}"));
1161+
}
11551162

11561163
return Err(err.into());
11571164
}
@@ -1221,9 +1228,21 @@ fn fetch_with_cli(
12211228
.env_remove("GIT_OBJECT_DIRECTORY")
12221229
.env_remove("GIT_ALTERNATE_OBJECT_DIRECTORIES")
12231230
.cwd(repo.path());
1231+
12241232
gctx.shell()
12251233
.verbose(|s| s.status("Running", &cmd.to_string()))?;
1226-
cmd.exec()?;
1234+
1235+
let revspec_id: String = refspecs
1236+
.iter()
1237+
.map(|s| s.split(':').next().unwrap_or("").to_string())
1238+
.collect();
1239+
1240+
cmd.exec().with_context(|| {
1241+
format!(
1242+
"Failed to fetch via Github fast path \nrevspec {:?} not found",
1243+
revspec_id
1244+
)
1245+
})?;
12271246
Ok(())
12281247
}
12291248

tests/testsuite/git.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,6 +4052,90 @@ src/lib.rs
40524052
.run();
40534053
}
40544054

4055+
#[cargo_test(public_network_test)]
4056+
fn github_fastpath_error_message() {
4057+
let p = project()
4058+
.file(
4059+
"Cargo.toml",
4060+
r#"
4061+
[package]
4062+
name = "foo"
4063+
version = "0.1.0"
4064+
edition = "2015"
4065+
4066+
[dependencies]
4067+
bitflags = { git = "https://github.com/rust-lang/bitflags.git", rev="11111b376b93484341c68fbca3ca110ae5cd2790" }
4068+
"#,
4069+
)
4070+
.file("src/lib.rs", "")
4071+
.build();
4072+
p.cargo("fetch")
4073+
.env("CARGO_NET_GIT_FETCH_WITH_CLI", "true")
4074+
.with_status(101)
4075+
.with_stderr_data(str![[r#"
4076+
[UPDATING] git repository `https://github.com/rust-lang/bitflags.git`
4077+
fatal: remote [ERROR] upload-pack: not our ref 11111b376b93484341c68fbca3ca110ae5cd2790
4078+
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
4079+
4080+
Caused by:
4081+
failed to load source for dependency `bitflags`
4082+
4083+
Caused by:
4084+
Unable to update https://github.com/rust-lang/bitflags.git?rev=11111b376b93484341c68fbca3ca110ae5cd2790
4085+
4086+
Caused by:
4087+
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
4088+
4089+
Caused by:
4090+
Failed to fetch via Github fast path
4091+
revspec "+11111b376b93484341c68fbca3ca110ae5cd2790" not found
4092+
4093+
Caused by:
4094+
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)
4095+
4096+
"#]])
4097+
.run();
4098+
}
4099+
4100+
#[cargo_test]
4101+
fn git_fetch_cli_false() {
4102+
let p = project()
4103+
.file(
4104+
"Cargo.toml",
4105+
r#"
4106+
[package]
4107+
name = "foo"
4108+
version = "0.1.0"
4109+
edition = "2015"
4110+
4111+
[dependencies]
4112+
bitflags = { git = "https://github.com/rust-lang/bitflags.git", rev="11111b376b93484341c68fbca3ca110ae5cd2790" }
4113+
"#,
4114+
)
4115+
.file("src/lib.rs", "")
4116+
.build();
4117+
p.cargo("fetch")
4118+
.with_status(101)
4119+
.with_stderr_data(str![[r#"
4120+
[UPDATING] git repository `https://github.com/rust-lang/bitflags.git`
4121+
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
4122+
4123+
Caused by:
4124+
failed to load source for dependency `bitflags`
4125+
4126+
Caused by:
4127+
Unable to update https://github.com/rust-lang/bitflags.git?rev=11111b376b93484341c68fbca3ca110ae5cd2790
4128+
4129+
Caused by:
4130+
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
4131+
4132+
Caused by:
4133+
refspec +11111b376b93484341c68fbca3ca110ae5cd2790 not found on https://github.com/rust-lang/bitflags.git
4134+
4135+
"#]])
4136+
.run();
4137+
}
4138+
40554139
#[cargo_test]
40564140
fn git_worktree_with_bare_original_repo() {
40574141
let project = project().build();

0 commit comments

Comments
 (0)