Skip to content

Commit 2aaebcb

Browse files
committed
Only fetch single object in shallow mode for compatibility
1 parent 99316c8 commit 2aaebcb

File tree

2 files changed

+14
-47
lines changed

2 files changed

+14
-47
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,15 @@ pub fn fetch(
900900
refspecs.push(format!("+{0}:{0}", rev));
901901
} else if let Some(oid_to_fetch) = oid_to_fetch {
902902
refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch));
903-
} else if rev.parse::<Oid>().is_ok() {
904-
// There is a specific commit to fetch and we will just do so in shallow-mode only
905-
// to not disturb the previous logic. Note that with typical settings for shallowing,
906-
// we will just fetch a single `rev` as single commit.
903+
} else if !matches!(shallow, gix::remote::fetch::Shallow::NoChange)
904+
&& rev.parse::<Oid>().is_ok()
905+
{
906+
// There is a specific commit to fetch and we will do so in shallow-mode only
907+
// to not disturb the previous logic.
908+
// Note that with typical settings for shallowing, we will just fetch a single `rev`
909+
// as single commit.
910+
// The reason we write to `refs/remotes/origin/HEAD` is that it's of special significance
911+
// when during `GitReference::resolve()`, but otherwise it shouldn't matter.
907912
refspecs.push(format!("+{0}:refs/remotes/origin/HEAD", rev));
908913
} else {
909914
// We don't know what the rev will point to. To handle this

tests/testsuite/git.rs

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -948,13 +948,6 @@ fn dep_with_bad_submodule() {
948948
None,
949949
)
950950
.unwrap();
951-
std::fs::remove_file(
952-
repo.path()
953-
.join("objects")
954-
.join(&commit.id().to_string()[..2])
955-
.join(&commit.id().to_string()[2..]),
956-
)
957-
.unwrap();
958951

959952
let p = project
960953
.file(
@@ -979,36 +972,9 @@ fn dep_with_bad_submodule() {
979972
"extern crate dep1; pub fn foo() { dep1::dep() }",
980973
)
981974
.build();
982-
let expected = if cargo_uses_gitoxide() {
983-
format!(
984-
"\
985-
[UPDATING] git repository [..]
986-
[UPDATING] git submodule `file://[..]/dep2`
987-
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
988-
989-
Caused by:
990-
failed to load source for dependency `dep1`
991-
992-
Caused by:
993-
Unable to update {}
994-
995-
Caused by:
996-
failed to update submodule `src`
997975

998-
Caused by:
999-
failed to fetch submodule `src` from [..]
1000-
1001-
Caused by:
1002-
Could not decode server reply
1003-
1004-
Caused by:
1005-
upload-pack: not our ref [..]
1006-
",
1007-
path2url(git_project.root())
1008-
)
1009-
} else {
1010-
format!(
1011-
"\
976+
let expected = format!(
977+
"\
1012978
[UPDATING] git repository [..]
1013979
[UPDATING] git submodule `file://[..]/dep2`
1014980
[ERROR] failed to get `dep1` as a dependency of package `foo v0.5.0 [..]`
@@ -1023,14 +989,10 @@ Caused by:
1023989
failed to update submodule `src`
1024990
1025991
Caused by:
1026-
failed to fetch submodule `src` from [..]
1027-
1028-
Caused by:
1029-
target OID for the reference doesn't exist on the repository; class=Reference (4)
992+
object not found - no match for id [..]
1030993
",
1031-
path2url(git_project.root())
1032-
)
1033-
};
994+
path2url(git_project.root())
995+
);
1034996

1035997
p.cargo("check")
1036998
.with_stderr(expected)

0 commit comments

Comments
 (0)