From 2aaebcbcaa66b799a807ba67d1ee7b6b44f7bdc7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 29 Apr 2023 14:22:33 +0200 Subject: [PATCH] Only fetch single object in shallow mode for compatibility --- src/cargo/sources/git/utils.rs | 13 ++++++--- tests/testsuite/git.rs | 50 ++++------------------------------ 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index b11a367c6..c14d1daf3 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -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::().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::().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 diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 7c9cb6a2b..32d0730c1 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -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)