tame_index::utils::git

Function write_fetch_head

Source
pub fn write_fetch_head(
    repo: &Repository,
    fetch: &Outcome,
    remote: &Remote<'_>,
) -> Result<ObjectId, Error>
Available on crate feature __git only.
Expand description

Writes the FETCH_HEAD for the specified fetch outcome to the specified git repository

This function is narrowly focused on on writing a FETCH_HEAD that contains exactly two pieces of information, the id of the commit pointed to by the remote HEAD, and, if it exists, the same id with the remote branch whose HEAD is the same. This focus gives use two things: 1. FETCH_HEAD that can be parsed to the correct remote HEAD by gix 1. A FETCH_HEAD that closely (or even exactly) matches that created by cargo via git or git2 when fetching only +HEAD:refs/remotes/origin/HEAD

Calling this function for the fetch outcome of a clone will write FETCH_HEAD just as if a normal fetch had occurred, but note that AFAICT neither git nor git2 does this, ie. a fresh clone will not have a FETCH_HEAD present. I don’t think that has negative implications, but if it does…just don’t call this function on the result of a clone :)

Note that the remote provided should be the same remote used for the fetch operation. The reason this is not just grabbed from the repo is because repositories may not have the configured remote, or the remote was modified (eg. replacing refspecs) before the fetch operation