generated from EmbarkStudios/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR makes a big change to how the RemoteGitIndex performs fetches (and clones) and subsequently reads blobs, to resolve issues discovered while doing obi1kenobi/cargo-semver-checks#506 Previously when performing a fetch, we also updated references so that HEAD pointed at the same commit as the remote HEAD. This works fine in local operation and in tests, but had a drawback, namely ``` Error: Failed to update references to their new position to match their remote locations Caused by: 0: The reflog could not be created or updated 1: reflog messages need a committer which isn't set ``` can occur in CI environments. My attempts to fix this...failed (configuring a committer name + email before editing references). Then I noticed frewsxcv/rust-crates-index#129 which....is just way better than that previous approach since we don't need to edit references any longer just to be able to use `repo.head_commit` for reading blobs, but rather just store the remote HEAD when opening/fetching and retrieving the tree to lookup blobs from that, sidestepping the whole issue with updating references. There is a big difference between that PR though, in that this PR also adds a function (`crate::utils::git::write_fetch_head`) to actually write a FETCH_HEAD _similarly_ to how cargo, via git or libgit2 writes FETCH_HEAD when performing a fetch on an index. This was done for 2 reasons: 1. Performing a fetch of an index via this crate will now update the index repository the same as cargo would, which makes this play nicer with cargo and thus the wider ecosystem 2. I had already done (a slightly worse) version of writing a FETCH_HEAD for [cargo-deny](https://github.com/EmbarkStudios/cargo-deny/blob/main/src/advisories/helpers/db.rs#L451-L457), because, AFAIK, retrieving the timestamp of the FETCH_HEAD file is by far the [most/only reliable](https://stackoverflow.com/questions/2993902/how-do-i-check-the-date-and-time-of-the-latest-git-pull-that-was-executed) way to determine when a fetch was last performed on a repository. The reason this was important for cargo deny is that it fetches advisory databases, but can decide _not_ to fetch them if the user doesn't want to perform network calls, however if they _never_ fetch from the remote advisory db they run the risk of mistakenly thinking everything is fine even if they have crate dependencies that have active advisories that were added/modified since the last time they fetched. So until `gix` adds support for writing FETCH_HEAD (which I think is planned, but couldn't find it), making this function public allows cargo-deny or others to also have a (simple, definitely not git/libgit2 compliant) way to write a FETCH_HEAD with gix.
- Loading branch information
1 parent
3a335ef
commit ee8c0d8
Showing
5 changed files
with
287 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.