Skip to content

Commit

Permalink
move 'exclude' up one level and dissolve 'repo' subcommand (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 22, 2022
1 parent 5cf08ce commit 8e5b796
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 79 deletions.
74 changes: 36 additions & 38 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use git_repository::bstr::io::BufReadExt;
use gitoxide_core as core;
use gitoxide_core::pack::verify;

use crate::plumbing::options::{commit, mailmap, odb, revision, tree};
use crate::plumbing::options::{commit, exclude, mailmap, odb, revision, tree};
use crate::{
plumbing::options::{free, repo, Args, Subcommands},
plumbing::options::{free, Args, Subcommands},
shared::pretty::prepare_and_run,
};

Expand Down Expand Up @@ -609,42 +609,40 @@ pub fn main() -> Result<()> {
move |_progress, out, err| core::repository::mailmap::entries(repository()?.into(), format, out, err),
),
},
Subcommands::Repository(repo::Platform { cmd }) => match cmd {
repo::Subcommands::Exclude { cmd } => match cmd {
repo::exclude::Subcommands::Query {
patterns,
pathspecs,
show_ignore_patterns,
} => prepare_and_run(
"repository-exclude-query",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
use git::bstr::ByteSlice;
core::repository::exclude::query(
repository()?.into(),
if pathspecs.is_empty() {
Box::new(
stdin_or_bail()?
.byte_lines()
.filter_map(Result::ok)
.filter_map(|line| git::path::Spec::from_bytes(line.as_bstr())),
) as Box<dyn Iterator<Item = git::path::Spec>>
} else {
Box::new(pathspecs.into_iter())
},
out,
core::repository::exclude::query::Options {
format,
show_ignore_patterns,
overrides: patterns,
},
)
},
),
},
Subcommands::Exclude { cmd } => match cmd {
exclude::Subcommands::Query {
patterns,
pathspecs,
show_ignore_patterns,
} => prepare_and_run(
"repository-exclude-query",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
use git::bstr::ByteSlice;
core::repository::exclude::query(
repository()?.into(),
if pathspecs.is_empty() {
Box::new(
stdin_or_bail()?
.byte_lines()
.filter_map(Result::ok)
.filter_map(|line| git::path::Spec::from_bytes(line.as_bstr())),
) as Box<dyn Iterator<Item = git::path::Spec>>
} else {
Box::new(pathspecs.into_iter())
},
out,
core::repository::exclude::query::Options {
format,
show_ignore_patterns,
overrides: patterns,
},
)
},
),
},
}?;
Ok(())
Expand Down
65 changes: 24 additions & 41 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ pub enum Subcommands {
#[clap(subcommand)]
cmd: mailmap::Subcommands,
},
/// Subcommands for interacting with entire git repositories
Repository(repo::Platform),
/// Interact with the exclude files like .gitignore.
Exclude {
#[clap(subcommand)]
cmd: exclude::Subcommands,
},
/// Subcommands that need no git repository to run.
#[clap(subcommand)]
Free(free::Subcommands),
Expand Down Expand Up @@ -580,48 +583,28 @@ pub mod free {
}
}

///
pub mod repo {
#[derive(Debug, clap::Parser)]
pub struct Platform {
/// Subcommands
#[clap(subcommand)]
pub cmd: Subcommands,
}
pub mod exclude {
use std::ffi::OsString;

use git_repository as git;

#[derive(Debug, clap::Subcommand)]
#[clap(visible_alias = "repo")]
pub enum Subcommands {
/// Interact with the exclude files like .gitignore.
Exclude {
#[clap(subcommand)]
cmd: exclude::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.
#[clap(long, short = 'p')]
patterns: Vec<OsString>,
/// The git path specifications to check for exclusion, or unset to read from stdin one per line.
#[clap(parse(try_from_os_str = std::convert::TryFrom::try_from))]
pathspecs: Vec<git::path::Spec>,
},
}

pub mod exclude {
use std::ffi::OsString;

use git_repository as git;

#[derive(Debug, clap::Subcommand)]
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.
#[clap(long, short = 'p')]
patterns: Vec<OsString>,
/// The git path specifications to check for exclusion, or unset to read from stdin one per line.
#[clap(parse(try_from_os_str = std::convert::TryFrom::try_from))]
pathspecs: Vec<git::path::Spec>,
},
}
}
}

0 comments on commit 8e5b796

Please sign in to comment.