Skip to content

Commit 6838bee

Browse files
committed
fix(git): added extra error context for a revision that doesn't exist
See issue #14621
1 parent db0edc3 commit 6838bee

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@ pub fn fetch(
944944

945945
let shallow = remote_kind.to_shallow_setting(repo.is_shallow(), gctx);
946946

947+
// Flag to keep track if the rev is a full commit hash
948+
let mut fast_path_rev: bool = false;
949+
947950
let oid_to_fetch = match github_fast_path(repo, remote_url, reference, gctx) {
948951
Ok(FastPathRev::UpToDate) => return Ok(()),
949952
Ok(FastPathRev::NeedsFetch(rev)) => Some(rev),
@@ -984,6 +987,7 @@ pub fn fetch(
984987
if rev.starts_with("refs/") {
985988
refspecs.push(format!("+{0}:{0}", rev));
986989
} else if let Some(oid_to_fetch) = oid_to_fetch {
990+
fast_path_rev = true;
987991
refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch));
988992
} else if !matches!(shallow, gix::remote::fetch::Shallow::NoChange)
989993
&& rev.parse::<Oid>().is_ok()
@@ -1006,13 +1010,20 @@ pub fn fetch(
10061010
}
10071011
}
10081012

1009-
if let Some(true) = gctx.net_config()?.git_fetch_with_cli {
1013+
let result = if let Some(true) = gctx.net_config()?.git_fetch_with_cli {
10101014
fetch_with_cli(repo, remote_url, &refspecs, tags, gctx)
10111015
} else if gctx.cli_unstable().gitoxide.map_or(false, |git| git.fetch) {
10121016
fetch_with_gitoxide(repo, remote_url, refspecs, tags, shallow, gctx)
10131017
} else {
10141018
fetch_with_libgit2(repo, remote_url, refspecs, tags, shallow, gctx)
1019+
};
1020+
1021+
if fast_path_rev {
1022+
if let Some(oid) = oid_to_fetch {
1023+
return result.with_context(|| format!("revision {} not found", oid));
1024+
}
10151025
}
1026+
result
10161027
}
10171028

10181029
/// `gitoxide` uses shallow locks to assure consistency when fetching to and to avoid races, and to write

tests/testsuite/git.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4086,6 +4086,9 @@ Caused by:
40864086
Caused by:
40874087
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
40884088
4089+
Caused by:
4090+
revision 11111b376b93484341c68fbca3ca110ae5cd2790 not found
4091+
40894092
Caused by:
40904093
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)
40914094
@@ -4128,6 +4131,9 @@ Caused by:
41284131
Caused by:
41294132
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
41304133
4134+
Caused by:
4135+
revision 11111b376b93484341c68fbca3ca110ae5cd2790 not found
4136+
41314137
Caused by:
41324138
network failure seems to have happened
41334139
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here

0 commit comments

Comments
 (0)