Skip to content

Commit

Permalink
Add --show-ignore-patterns to gix repo exclude query (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 30, 2022
1 parent e4f4c4b commit 09f904b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod query {
pub format: OutputFormat,
pub pathspecs: Vec<git::path::Spec>,
pub overrides: Vec<OsString>,
pub show_ignore_patterns: bool,
}
}

Expand All @@ -24,6 +25,7 @@ pub fn query(
overrides,
format,
pathspecs,
show_ignore_patterns,
}: query::Options,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
Expand All @@ -50,7 +52,7 @@ pub fn query(
let entry = cache.at_entry(path, is_dir, |oid, buf| repo.objects.find_blob(oid, buf))?;
let match_ = entry
.matching_exclude_pattern()
.and_then(|m| (!m.pattern.is_negative()).then(|| m));
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then(|| m));
match match_ {
Some(m) => writeln!(
out,
Expand Down
7 changes: 6 additions & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ pub fn main() -> Result<()> {
),
},
repo::Subcommands::Exclude { cmd } => match cmd {
repo::exclude::Subcommands::Query { patterns, pathspecs } => prepare_and_run(
repo::exclude::Subcommands::Query {
patterns,
pathspecs,
show_ignore_patterns,
} => prepare_and_run(
"repository-exclude-query",
verbose,
progress,
Expand All @@ -208,6 +212,7 @@ pub fn main() -> Result<()> {
core::repository::exclude::query::Options {
format,
pathspecs,
show_ignore_patterns,
overrides: patterns,
},
)
Expand Down
5 changes: 5 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ pub mod repo {
pub enum Subcommands {
/// Check if path-specs are excluded and print the result similar to `git check-ignore`.
Query {
/// Show actual ignore patterns instead of un-excluding an entry.
///
/// That way one can understand why an entry might not be excluded.
#[clap(long, short = 'i')]
show_ignore_patterns: bool,
/// Additional patterns to use for exclusions. They have the highest priority.
///
/// Useful for undoing previous patterns using the '!' prefix.
Expand Down

0 comments on commit 09f904b

Please sign in to comment.