Skip to content

Commit

Permalink
Support for overrides on the command-line (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 29, 2022
1 parent 5bf6b52 commit 7d98b21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
13 changes: 11 additions & 2 deletions gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ use git_repository as git;
pub mod query {
use crate::OutputFormat;
use git_repository as git;
use std::ffi::OsString;

pub struct Options {
pub format: OutputFormat,
pub pathspecs: Vec<git::path::Spec>,
pub overrides: Vec<OsString>,
}
}

pub fn query(
repo: git::Repository,
_out: impl io::Write,
query::Options { format, pathspecs: _ }: query::Options,
query::Options {
overrides,
format,
pathspecs: _,
}: query::Options,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("JSON output isn't implemented yet");
Expand All @@ -28,7 +34,10 @@ pub fn query(
.current()
.with_context(|| "Cannot check excludes without a current worktree")?;
let index = worktree.open_index()?;
worktree.excludes(&index.state, None)?; // TODO: support CLI overrides
worktree.excludes(
&index.state,
Some(git::attrs::MatchGroup::<git::attrs::Ignore>::from_overrides(overrides)),
)?;

todo!("impl");
}
8 changes: 6 additions & 2 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn main() -> Result<()> {
),
},
repo::Subcommands::Exclude { cmd } => match cmd {
repo::exclude::Subcommands::Query { pathspecs } => prepare_and_run(
repo::exclude::Subcommands::Query { patterns, pathspecs } => prepare_and_run(
"repository-exclude-query",
verbose,
progress,
Expand All @@ -205,7 +205,11 @@ pub fn main() -> Result<()> {
core::repository::exclude::query(
repository.into(),
out,
core::repository::exclude::query::Options { format, pathspecs },
core::repository::exclude::query::Options {
format,
pathspecs,
overrides: patterns,
},
)
},
),
Expand Down
6 changes: 6 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,17 @@ pub mod repo {

pub mod exclude {
use git_repository as git;
use std::ffi::OsString;

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Check if path-specs are excluded and print the result similar to `git check-ignore`.
Query {
/// Additional patterns to use for exclusions. They have the highest priority.
///
/// Useful for undoing previous patterns using the '!' prefix.
#[clap(long, short = 'p')]
patterns: Vec<OsString>,
/// The git path specifications to check for exclusion.
pathspecs: Vec<git::path::Spec>,
},
Expand Down

0 comments on commit 7d98b21

Please sign in to comment.