pub fn added_by(root: &Path, path: &Path) -> Result<Option<AddedBy>>Expand description
The commit that added path. It is the newest commit on HEAD’s
first-parent history whose tree has the file and whose first parent’s tree
does not.
A squash merge is that commit, and its subject carries the pull request number.
When that commit is a merge and another parent already has the file, the
file arrived with the merged branch. The walk then continues down that
parent’s first-parent history. A fragment merged from next links the pull
request that added it there, instead of the merge.
A merge titled with its pull request, Title (#N), may have branch commits
that name none. That merge is then the commit named instead. A repository
that merges with merge commits thus keeps its pull request links. The
deepest such merge on the way down wins.
The result is None in these cases:
- There is no repository, or HEAD does not track the file. A fixture outside git, or a fragment not committed yet, has no commit to name.
- A shallow clone ends before the adding commit. A commit listed in
.git/shallowis the boundary and counts as parentless, and naming it would link the wrong commit. - A parent exists but cannot be loaded. It is treated like the shallow boundary.
§Errors
Returns an error when the shallow boundary cannot be read, or when a tree or commit message on the walk cannot be read.