-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
gix attributes validate
to validate attributes and ignore aga…
…inst `git` as baseline. Use this command to test the entire index for ignored paths and their attributes and use `git check-attr` and `git check-ignore` to validate that `git` agrees. Collect all mismatches and print them.
- Loading branch information
Showing
7 changed files
with
479 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod query; | ||
pub use query::function::query; | ||
|
||
pub mod validate_baseline; | ||
pub use validate_baseline::function::validate_baseline; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::OutputFormat; | ||
|
||
pub struct Options { | ||
pub format: OutputFormat, | ||
pub statistics: bool, | ||
} | ||
|
||
pub(crate) mod function { | ||
use crate::repository::attributes::query::{attributes_cache, Options}; | ||
use crate::OutputFormat; | ||
use std::io; | ||
|
||
use anyhow::bail; | ||
use gix::prelude::FindExt; | ||
|
||
pub fn query( | ||
repo: gix::Repository, | ||
pathspecs: impl Iterator<Item = gix::path::Spec>, | ||
mut out: impl io::Write, | ||
mut err: impl io::Write, | ||
Options { format, statistics }: Options, | ||
) -> anyhow::Result<()> { | ||
if format != OutputFormat::Human { | ||
bail!("JSON output isn't implemented yet"); | ||
} | ||
|
||
let mut cache = attributes_cache(&repo)?; | ||
let prefix = repo.prefix().expect("worktree - we have an index by now")?; | ||
let mut matches = cache.attribute_matches(); | ||
|
||
for mut spec in pathspecs { | ||
for path in spec.apply_prefix(&prefix).items() { | ||
let is_dir = gix::path::from_bstr(path).metadata().ok().map(|m| m.is_dir()); | ||
let entry = cache.at_entry(path, is_dir, |oid, buf| repo.objects.find_blob(oid, buf))?; | ||
|
||
if !entry.matching_attributes(&mut matches) { | ||
continue; | ||
} | ||
for m in matches.iter() { | ||
writeln!( | ||
out, | ||
"{}:{}:{}\t{}\t{}", | ||
m.location.source.map(|p| p.to_string_lossy()).unwrap_or_default(), | ||
m.location.sequence_number, | ||
m.pattern, | ||
path, | ||
m.assignment | ||
)?; | ||
} | ||
} | ||
} | ||
|
||
if let Some(stats) = statistics.then(|| cache.take_statistics()) { | ||
out.flush()?; | ||
writeln!(err, "{:#?}", stats).ok(); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub(crate) fn attributes_cache(repo: &gix::Repository) -> anyhow::Result<gix::worktree::Cache> { | ||
let index = repo.index()?; | ||
Ok(repo.attributes( | ||
&index, | ||
gix::worktree::cache::state::attributes::Source::WorktreeThenIdMapping, | ||
gix::worktree::cache::state::ignore::Source::IdMapping, | ||
None, | ||
)?) | ||
} |
Oops, something went wrong.