pub fn check_path_modifications(
git_dir: &Path,
config: &GitConfig<'_>,
target_paths: &[&str],
ci_env: CiEnv,
) -> Result<PathFreshness, String>
Expand description
This function figures out if a set of paths was last modified upstream or if there are some local modifications made to them. It can be used to figure out if we should download artifacts from CI or rather build them locally.
The function assumes that at least a single upstream bors merge commit is in the local git history.
target_paths
should be a non-empty slice of paths (git pathspec
s) relative to git_dir
whose modifications would invalidate the artifact.
Each pathspec can also be a negative match, i.e. :!foo
. This matches changes outside
the foo
directory.
See https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
for how git pathspec
works.
The function behaves differently in CI and outside CI.
-
Outside CI, we want to find out if
target_paths
were modified in some local commit on top of the latest upstream commit that is available in local git history. If not, we try to find the most recent upstream commit (which we assume are commits made by bors) that modifiedtarget_paths
. We don’t want to simply take the latest master commit to avoid changing the output of this function frequently after rebasing on the latest master branch even iftarget_paths
were not modified upstream in the meantime. In that case we would be redownloading CI artifacts unnecessarily. -
In CI, we use a shallow clone of depth 2, i.e., we fetch only a single parent commit (which will be the most recent bors merge commit) and do not have access to the full git history. Luckily, we only need to distinguish between two situations:
- The current PR made modifications to
target_paths
. In that case, a build is typically necessary. - The current PR did not make modifications to
target_paths
. In that case we simply take the latest upstream commit, because on CI there is no need to avoid redownloading.