Skip to content

Commit

Permalink
feat: gix config lists all entries of all configuration files git c…
Browse files Browse the repository at this point in the history
…onsiders. (#331)

Filters allow to narrow down the output.
  • Loading branch information
Byron committed Jul 22, 2022
1 parent a437abe commit d99453e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
1 change: 1 addition & 0 deletions git-repository/src/repository/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::config;

/// Configuration
impl crate::Repository {
/// Return
/// Return a snapshot of the configuration as seen upon opening the repository.
pub fn config_snapshot(&self) -> config::Snapshot<'_> {
config::Snapshot { repo: self }
Expand Down
18 changes: 18 additions & 0 deletions gitoxide-core/src/repository/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::OutputFormat;
use anyhow::{bail, Result};
use git_repository as git;

pub fn list(
repo: git::Repository,
_filters: Vec<String>,
format: OutputFormat,
out: impl std::io::Write,
) -> Result<()> {
if format != OutputFormat::Human {
bail!("Only human output format is supported at the moment");
}
let config = repo.config_snapshot();
let config = config.plumbing();
config.write_to(out)?;
Ok(())
}
2 changes: 2 additions & 0 deletions gitoxide-core/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub fn init(directory: Option<PathBuf>) -> Result<git::discover::repository::Pat
.with_context(|| "Repository initialization failed")
}

pub mod config;

pub mod tree;

pub mod commit;
Expand Down
29 changes: 19 additions & 10 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use git_repository::bstr::io::BufReadExt;
use gitoxide_core as core;
use gitoxide_core::pack::verify;

use crate::plumbing::options::{commit, exclude, mailmap, odb, revision, tree};
use crate::plumbing::options::{commit, config, exclude, mailmap, odb, revision, tree};
use crate::{
plumbing::options::{free, Args, Subcommands},
shared::pretty::prepare_and_run,
Expand Down Expand Up @@ -76,6 +76,15 @@ pub fn main() -> Result<()> {
})?;

match cmd {
Subcommands::Config(config::Platform { filter }) => prepare_and_run(
"config-list",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::repository::config::list(repository()?.into(), filter, format, out),
)
.map(|_| ()),
Subcommands::Free(subcommands) => match subcommands {
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
free::Subcommands::Remote(subcommands) => match subcommands {
Expand Down Expand Up @@ -483,7 +492,7 @@ pub fn main() -> Result<()> {
re_encode,
},
} => prepare_and_run(
"repository-verify",
"verify",
verbose,
progress,
progress_keep_open,
Expand All @@ -505,7 +514,7 @@ pub fn main() -> Result<()> {
),
Subcommands::Revision(cmd) => match cmd {
revision::Subcommands::Explain { spec } => prepare_and_run(
"repository-commit-describe",
"commit-describe",
verbose,
progress,
progress_keep_open,
Expand All @@ -524,7 +533,7 @@ pub fn main() -> Result<()> {
max_candidates,
rev_spec,
} => prepare_and_run(
"repository-commit-describe",
"commit-describe",
verbose,
progress,
progress_keep_open,
Expand Down Expand Up @@ -554,7 +563,7 @@ pub fn main() -> Result<()> {
recursive,
extended,
} => prepare_and_run(
"repository-tree-entries",
"tree-entries",
verbose,
progress,
progress_keep_open,
Expand All @@ -571,7 +580,7 @@ pub fn main() -> Result<()> {
},
),
tree::Subcommands::Info { treeish, extended } => prepare_and_run(
"repository-tree-info",
"tree-info",
verbose,
progress,
progress_keep_open,
Expand All @@ -583,15 +592,15 @@ pub fn main() -> Result<()> {
},
Subcommands::Odb(cmd) => match cmd {
odb::Subcommands::Entries => prepare_and_run(
"repository-odb-entries",
"odb-entries",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::repository::odb::entries(repository()?.into(), format, out),
),
odb::Subcommands::Info => prepare_and_run(
"repository-odb-info",
"odb-info",
verbose,
progress,
progress_keep_open,
Expand All @@ -601,7 +610,7 @@ pub fn main() -> Result<()> {
},
Subcommands::Mailmap(cmd) => match cmd {
mailmap::Subcommands::Entries => prepare_and_run(
"repository-mailmap-entries",
"mailmap-entries",
verbose,
progress,
progress_keep_open,
Expand All @@ -615,7 +624,7 @@ pub fn main() -> Result<()> {
pathspecs,
show_ignore_patterns,
} => prepare_and_run(
"repository-exclude-query",
"exclude-query",
verbose,
progress,
progress_keep_open,
Expand Down
11 changes: 11 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,22 @@ pub enum Subcommands {
/// Interact with the exclude files like .gitignore.
#[clap(subcommand)]
Exclude(exclude::Subcommands),
Config(config::Platform),
/// Subcommands that need no git repository to run.
#[clap(subcommand)]
Free(free::Subcommands),
}

pub mod config {
/// Print all entries in a configuration file or access other sub-commands
#[derive(Debug, clap::Parser)]
#[clap(subcommand_required(false))]
pub struct Platform {
/// The filter terms to limit the output to matching sections and values only.
pub filter: Vec<String>,
}
}

pub mod mailmap {
#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
Expand Down

0 comments on commit d99453e

Please sign in to comment.