logo
pub async fn from_origin(
    path: impl AsRef<Path>
) -> (Vec<IgnoreFile>, Vec<Error>)
Expand description

Finds all ignore files in the given directory and subdirectories.

This considers:

  • Git ignore files (.gitignore)
  • Mercurial ignore files (.hgignore)
  • Tool-generic .ignore files
  • .git/info/exclude files in the path directory only
  • Git configurable project ignore files (with core.excludesFile in .git/config)

Importantly, this should be called from the origin of the project, not a subfolder. This function will not discover the project origin, and will not traverse parent directories. Use the project::origins function for that.

This function also does not distinguish between project folder types, and collects all files for all supported VCSs and other project types. Use the applies_to field to filter the results.

All errors (permissions, etc) are collected and returned alongside the ignore files: you may want to show them to the user while still using whatever ignores were successfully found. Errors from files not being found are silently ignored (the files are just not returned).

Special case: project-local git config specifying core.excludesFile

If the project’s .git/config specifies a value for core.excludesFile, this function will return an IgnoreFile { path: path/to/that/file, applies_in: None, applies_to: Some(ProjectType::Git) }. This is the only case in which the applies_in field is None from this function. When such is received the global Git ignore files found by from_environment() should be ignored.