Fix implementation of GitDatabase::contains (#4698)

## Summary

`GitDatabase::contains` previously only parsed the commit to see if it
was a valid hash and didn't verify if the commit existed in the object
database. This led to the database never being updated.

Resolves https://github.com/astral-sh/uv/issues/4378.

## Test Plan

Added a test that fails without this change.
This commit is contained in:
Ibraheem Ahmed 2024-07-01 13:01:29 -04:00 committed by GitHub
parent 5715def24b
commit 58499439d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 3 deletions

View file

@ -175,7 +175,7 @@ impl GitRepository {
})
}
/// Fetches the object ID of the given `refname`.
/// Parses the object ID of the given `refname`.
fn rev_parse(&self, refname: &str) -> Result<GitOid> {
let result = ProcessBuilder::new("git")
.arg("rev-parse")
@ -295,9 +295,9 @@ impl GitDatabase {
Ok(result)
}
/// Checks if the database contains the object of this `oid`.
/// Checks if `oid` resolves to a commit in this database.
pub(crate) fn contains(&self, oid: GitOid) -> bool {
self.repo.rev_parse(oid.as_str()).is_ok()
self.repo.rev_parse(&format!("{oid}^0")).is_ok()
}
}