Support no-{global,project,vcs}-ignore

This commit is contained in:
Félix Saparelli 2021-12-29 19:19:43 +13:00
parent be4b184cd0
commit e2f6fe147a
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
2 changed files with 35 additions and 7 deletions

View File

@ -98,7 +98,7 @@ pub fn get_args(tagged_filterer: bool) -> Result<ArgMatches<'static>> {
.help_heading(Some(OPTSET_FILTERING))
.help("Skip auto-loading of VCS (Git, etc) ignore files")
.long("no-vcs-ignore"))
.arg(Arg::with_name("no-ignore") // TODO
.arg(Arg::with_name("no-project-ignore") // TODO
.help_heading(Some(OPTSET_FILTERING))
.help("Skip auto-loading of project ignore files (.gitignore, .ignore, etc)")
.long("no-ignore"))

View File

@ -34,7 +34,7 @@ pub async fn dirs(args: &ArgMatches<'static>) -> Result<(PathBuf, PathBuf)> {
Ok((project_origin, workdir))
}
pub async fn ignores(_args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<IgnoreFile>> {
pub async fn ignores(args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<IgnoreFile>> {
let vcs_types = project::types(origin)
.await
.into_iter()
@ -46,6 +46,8 @@ pub async fn ignores(_args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<I
// TODO: handle errors
debug!(?ignores, "discovered ignore files from project origin");
// TODO: use drain_ignore instead for x = x.filter()... when that stabilises
let mut skip_git_global_excludes = false;
if !vcs_types.is_empty() {
ignores = ignores
@ -67,7 +69,6 @@ pub async fn ignores(_args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<I
})
.collect::<Vec<_>>();
debug!(?ignores, "filtered ignores to only those for project vcs");
// TODO: use drain_ignore when that stabilises
}
let (mut global_ignores, _errors) = ignore_files::from_environment().await;
@ -92,7 +93,6 @@ pub async fn ignores(_args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<I
?global_ignores,
"filtered global ignores to exclude global git ignores"
);
// TODO: use drain_ignore when that stabilises
}
if !vcs_types.is_empty() {
@ -103,9 +103,37 @@ pub async fn ignores(_args: &ArgMatches<'static>, origin: &Path) -> Result<Vec<I
debug!(?ignores, "combined and applied final filter over ignores");
}
// TODO: --no-ignore
// TODO: --no-vcs-ignore
// TODO: --no-global-ignore
if args.is_present("no-project-ignore") {
ignores = ignores
.into_iter()
.filter(|ig| {
!ig.applies_in
.as_ref()
.map_or(false, |p| p.starts_with(&origin))
})
.collect::<Vec<_>>();
debug!(
?ignores,
"filtered ignores to exclude project-local ignores"
);
}
if args.is_present("no-global-ignore") {
ignores = ignores
.into_iter()
.filter(|ig| !matches!(ig.applies_in, None))
.collect::<Vec<_>>();
debug!(?ignores, "filtered ignores to exclude global ignores");
}
if args.is_present("no-vcs-ignore") {
ignores = ignores
.into_iter()
.filter(|ig| matches!(ig.applies_to, None))
.collect::<Vec<_>>();
debug!(?ignores, "filtered ignores to exclude VCS-specific ignores");
}
// TODO: --no-default-ignore (whatever that was)
Ok(ignores)