Skip to content

Commit

Permalink
fix(git): added extra error context for a revision that doesn't exist
Browse files Browse the repository at this point in the history
See issue #14621
  • Loading branch information
dacianpascu06 committed Nov 17, 2024
1 parent 309b2ce commit a247968
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,9 @@ pub fn fetch(

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

// Flag to keep track if the rev is a full commit hash
let mut fast_path_rev: bool = false;

let oid_to_fetch = match github_fast_path(repo, remote_url, reference, gctx) {
Ok(FastPathRev::UpToDate) => return Ok(()),
Ok(FastPathRev::NeedsFetch(rev)) => Some(rev),
Expand Down Expand Up @@ -984,6 +987,7 @@ pub fn fetch(
if rev.starts_with("refs/") {
refspecs.push(format!("+{0}:{0}", rev));
} else if let Some(oid_to_fetch) = oid_to_fetch {
fast_path_rev = true;
refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch));
} else if !matches!(shallow, gix::remote::fetch::Shallow::NoChange)
&& rev.parse::<Oid>().is_ok()
Expand All @@ -1006,13 +1010,20 @@ pub fn fetch(
}
}

if let Some(true) = gctx.net_config()?.git_fetch_with_cli {
let result = if let Some(true) = gctx.net_config()?.git_fetch_with_cli {
fetch_with_cli(repo, remote_url, &refspecs, tags, gctx)
} else if gctx.cli_unstable().gitoxide.map_or(false, |git| git.fetch) {
fetch_with_gitoxide(repo, remote_url, refspecs, tags, shallow, gctx)
} else {
fetch_with_libgit2(repo, remote_url, refspecs, tags, shallow, gctx)
};

if fast_path_rev {
if let Some(oid) = oid_to_fetch {
return result.with_context(|| format!("revision {} not found", oid));
}
}
result
}

/// `gitoxide` uses shallow locks to assure consistency when fetching to and to avoid races, and to write
Expand Down
6 changes: 6 additions & 0 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4086,6 +4086,9 @@ Caused by:
Caused by:
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
Caused by:
revision 11111b376b93484341c68fbca3ca110ae5cd2790 not found
Caused by:
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)
Expand Down Expand Up @@ -4125,6 +4128,9 @@ Caused by:
Caused by:
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
Caused by:
revision 11111b376b93484341c68fbca3ca110ae5cd2790 not found
...
"#]])
.run();
Expand Down

0 comments on commit a247968

Please sign in to comment.