Only fetch single object in shallow mode for compatibility

This commit is contained in:
Sebastian Thiel 2023-04-29 14:22:33 +02:00
parent 99316c8e43
commit 2aaebcbcaa
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
2 changed files with 15 additions and 48 deletions

View File

@ -900,10 +900,15 @@ pub fn fetch(
refspecs.push(format!("+{0}:{0}", rev));
} else if let Some(oid_to_fetch) = oid_to_fetch {
refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch));
} else if rev.parse::<Oid>().is_ok() {
// There is a specific commit to fetch and we will just do so in shallow-mode only
// to not disturb the previous logic. Note that with typical settings for shallowing,
// we will just fetch a single `rev` as single commit.
} else if !matches!(shallow, gix::remote::fetch::Shallow::NoChange)
&& rev.parse::<Oid>().is_ok()
{
// There is a specific commit to fetch and we will do so in shallow-mode only
// to not disturb the previous logic.
// Note that with typical settings for shallowing, we will just fetch a single `rev`
// as single commit.
// The reason we write to `refs/remotes/origin/HEAD` is that it's of special significance
// when during `GitReference::resolve()`, but otherwise it shouldn't matter.
refspecs.push(format!("+{0}:refs/remotes/origin/HEAD", rev));
} else {
// We don't know what the rev will point to. To handle this

View File

@ -948,13 +948,6 @@ fn dep_with_bad_submodule() {
None,
)
.unwrap();
std::fs::remove_file(
repo.path()
.join("objects")
.join(&commit.id().to_string()[..2])
.join(&commit.id().to_string()[2..]),
)
.unwrap();
let p = project
.file(
@ -979,9 +972,9 @@ fn dep_with_bad_submodule() {
"extern crate dep1; pub fn foo() { dep1::dep() }",
)
.build();
let expected = if cargo_uses_gitoxide() {
format!(
"\
let expected = format!(
"\
[UPDATING] git repository [..]
[UPDATING] git submodule `file://[..]/dep2`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
@ -996,41 +989,10 @@ Caused by:
failed to update submodule `src`
Caused by:
failed to fetch submodule `src` from [..]
Caused by:
Could not decode server reply
Caused by:
upload-pack: not our ref [..]
object not found - no match for id [..]
",
path2url(git_project.root())
)
} else {
format!(
"\
[UPDATING] git repository [..]
[UPDATING] git submodule `file://[..]/dep2`
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
Caused by:
failed to load source for dependency `dep1`
Caused by:
Unable to update {}
Caused by:
failed to update submodule `src`
Caused by:
failed to fetch submodule `src` from [..]
Caused by:
target OID for the reference doesn't exist on the repository; class=Reference (4)
",
path2url(git_project.root())
)
};
path2url(git_project.root())
);
p.cargo("check")
.with_stderr(expected)