Skip to content

Commit 8e5b796

Browse files
committed
move 'exclude' up one level and dissolve 'repo' subcommand (#331)
1 parent 5cf08ce commit 8e5b796

File tree

2 files changed

+60
-79
lines changed

2 files changed

+60
-79
lines changed

Diff for: src/plumbing/main.rs

+36-38
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use git_repository::bstr::io::BufReadExt;
1313
use gitoxide_core as core;
1414
use gitoxide_core::pack::verify;
1515

16-
use crate::plumbing::options::{commit, mailmap, odb, revision, tree};
16+
use crate::plumbing::options::{commit, exclude, mailmap, odb, revision, tree};
1717
use crate::{
18-
plumbing::options::{free, repo, Args, Subcommands},
18+
plumbing::options::{free, Args, Subcommands},
1919
shared::pretty::prepare_and_run,
2020
};
2121

@@ -609,42 +609,40 @@ pub fn main() -> Result<()> {
609609
move |_progress, out, err| core::repository::mailmap::entries(repository()?.into(), format, out, err),
610610
),
611611
},
612-
Subcommands::Repository(repo::Platform { cmd }) => match cmd {
613-
repo::Subcommands::Exclude { cmd } => match cmd {
614-
repo::exclude::Subcommands::Query {
615-
patterns,
616-
pathspecs,
617-
show_ignore_patterns,
618-
} => prepare_and_run(
619-
"repository-exclude-query",
620-
verbose,
621-
progress,
622-
progress_keep_open,
623-
None,
624-
move |_progress, out, _err| {
625-
use git::bstr::ByteSlice;
626-
core::repository::exclude::query(
627-
repository()?.into(),
628-
if pathspecs.is_empty() {
629-
Box::new(
630-
stdin_or_bail()?
631-
.byte_lines()
632-
.filter_map(Result::ok)
633-
.filter_map(|line| git::path::Spec::from_bytes(line.as_bstr())),
634-
) as Box<dyn Iterator<Item = git::path::Spec>>
635-
} else {
636-
Box::new(pathspecs.into_iter())
637-
},
638-
out,
639-
core::repository::exclude::query::Options {
640-
format,
641-
show_ignore_patterns,
642-
overrides: patterns,
643-
},
644-
)
645-
},
646-
),
647-
},
612+
Subcommands::Exclude { cmd } => match cmd {
613+
exclude::Subcommands::Query {
614+
patterns,
615+
pathspecs,
616+
show_ignore_patterns,
617+
} => prepare_and_run(
618+
"repository-exclude-query",
619+
verbose,
620+
progress,
621+
progress_keep_open,
622+
None,
623+
move |_progress, out, _err| {
624+
use git::bstr::ByteSlice;
625+
core::repository::exclude::query(
626+
repository()?.into(),
627+
if pathspecs.is_empty() {
628+
Box::new(
629+
stdin_or_bail()?
630+
.byte_lines()
631+
.filter_map(Result::ok)
632+
.filter_map(|line| git::path::Spec::from_bytes(line.as_bstr())),
633+
) as Box<dyn Iterator<Item = git::path::Spec>>
634+
} else {
635+
Box::new(pathspecs.into_iter())
636+
},
637+
out,
638+
core::repository::exclude::query::Options {
639+
format,
640+
show_ignore_patterns,
641+
overrides: patterns,
642+
},
643+
)
644+
},
645+
),
648646
},
649647
}?;
650648
Ok(())

Diff for: src/plumbing/options.rs

+24-41
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ pub enum Subcommands {
8181
#[clap(subcommand)]
8282
cmd: mailmap::Subcommands,
8383
},
84-
/// Subcommands for interacting with entire git repositories
85-
Repository(repo::Platform),
84+
/// Interact with the exclude files like .gitignore.
85+
Exclude {
86+
#[clap(subcommand)]
87+
cmd: exclude::Subcommands,
88+
},
8689
/// Subcommands that need no git repository to run.
8790
#[clap(subcommand)]
8891
Free(free::Subcommands),
@@ -580,48 +583,28 @@ pub mod free {
580583
}
581584
}
582585

583-
///
584-
pub mod repo {
585-
#[derive(Debug, clap::Parser)]
586-
pub struct Platform {
587-
/// Subcommands
588-
#[clap(subcommand)]
589-
pub cmd: Subcommands,
590-
}
586+
pub mod exclude {
587+
use std::ffi::OsString;
588+
589+
use git_repository as git;
591590

592591
#[derive(Debug, clap::Subcommand)]
593-
#[clap(visible_alias = "repo")]
594592
pub enum Subcommands {
595-
/// Interact with the exclude files like .gitignore.
596-
Exclude {
597-
#[clap(subcommand)]
598-
cmd: exclude::Subcommands,
593+
/// Check if path-specs are excluded and print the result similar to `git check-ignore`.
594+
Query {
595+
/// Show actual ignore patterns instead of un-excluding an entry.
596+
///
597+
/// That way one can understand why an entry might not be excluded.
598+
#[clap(long, short = 'i')]
599+
show_ignore_patterns: bool,
600+
/// Additional patterns to use for exclusions. They have the highest priority.
601+
///
602+
/// Useful for undoing previous patterns using the '!' prefix.
603+
#[clap(long, short = 'p')]
604+
patterns: Vec<OsString>,
605+
/// The git path specifications to check for exclusion, or unset to read from stdin one per line.
606+
#[clap(parse(try_from_os_str = std::convert::TryFrom::try_from))]
607+
pathspecs: Vec<git::path::Spec>,
599608
},
600609
}
601-
602-
pub mod exclude {
603-
use std::ffi::OsString;
604-
605-
use git_repository as git;
606-
607-
#[derive(Debug, clap::Subcommand)]
608-
pub enum Subcommands {
609-
/// Check if path-specs are excluded and print the result similar to `git check-ignore`.
610-
Query {
611-
/// Show actual ignore patterns instead of un-excluding an entry.
612-
///
613-
/// That way one can understand why an entry might not be excluded.
614-
#[clap(long, short = 'i')]
615-
show_ignore_patterns: bool,
616-
/// Additional patterns to use for exclusions. They have the highest priority.
617-
///
618-
/// Useful for undoing previous patterns using the '!' prefix.
619-
#[clap(long, short = 'p')]
620-
patterns: Vec<OsString>,
621-
/// The git path specifications to check for exclusion, or unset to read from stdin one per line.
622-
#[clap(parse(try_from_os_str = std::convert::TryFrom::try_from))]
623-
pathspecs: Vec<git::path::Spec>,
624-
},
625-
}
626-
}
627610
}

0 commit comments

Comments
 (0)