Skip to content

Commit 43a5dee

Browse files
committed
fix(git): added extra error context for a revision that doesn't exist
See issue #14621
1 parent 309b2ce commit 43a5dee

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4087,7 +4087,10 @@ Caused by:
40874087
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
40884088
40894089
Caused by:
4090-
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)
4090+
revision 11111b376b93484341c68fbca3ca110ae5cd2790 not found
4091+
4092+
Caused by:
4093+
process didn't exit successfully: `git fetch --no-tags --force --update-head-ok [..]
40914094
40924095
"#]])
40934096
.run();
@@ -4125,6 +4128,9 @@ Caused by:
41254128
41264129
Caused by:
41274130
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
4131+
4132+
Caused by:
4133+
revision 11111b376b93484341c68fbca3ca110ae5cd2790 not found
41284134
...
41294135
"#]])
41304136
.run();

0 commit comments

Comments
 (0)