History

Support for -c CLI config overrides in `gix config`. (#450)

It's special as it creates its own repository.

Sebastian Thiel committed 4 years ago

Commit 19c17461 parent 5d22e293 files · +28 −19Browse files

Unified · Split

3 files
  1. git-repository/src/config/snapshot.rs +4 −4
  2. gitoxide-core/src/repository/config.rs +4 −1
  3. src/plumbing/main.rs +20 −14
git-repository/src/config/snapshot.rs+4−4
@@ -83,7 +83,7 @@ impl<'repo> Snapshot<'repo> { · 82 unmodified lines
8383
8484 ///
8585 pub mod apply_cli_overrides {
86− use crate::bstr::{BString, ByteSlice};
86+ use crate::bstr::{BStr, BString, ByteSlice};
8787 use crate::config::SnapshotMut;
8888 use std::convert::TryFrom;
8989
@@ -105,13 +105,13 @@ pub mod apply_cli_overrides { · 15 unmodified lines
105105 impl SnapshotMut<'_> {
106106 /// Apply configuration values of the form `core.abbrev=5` or `remote.origin.url = foo` or `core.bool-implicit-true`
107107 /// to the repository configuration, marked with [source CLI][git_config::Source::Cli].
108− pub fn apply_cli_overrides(
108+ pub fn apply_cli_overrides<'a>(
109109 &mut self,
110− values: impl IntoIterator<Item = impl Into<BString>>,
110+ values: impl IntoIterator<Item = impl AsRef<BStr>>,
111111 ) -> Result<(), Error> {
112112 let mut file = git_config::File::new(git_config::file::Metadata::from(git_config::Source::Cli));
113113 for key_value in values {
114− let key_value = key_value.into();
114+ let key_value = key_value.as_ref();
115115 let mut tokens = key_value.splitn(2, |b| *b == b'=').map(|v| v.trim());
116116 let key = tokens.next().expect("always one value").as_bstr();
117117 let value = tokens.next();
gitoxide-core/src/repository/config.rs+4−1
@@ -1,18 +1,21 @@
11 use anyhow::{bail, Result};
22 use git_repository as git;
3+use git_repository::bstr::BString;
34
45 use crate::OutputFormat;
56
67 pub fn list(
78 repo: git::Repository,
89 filters: Vec<String>,
10+ overrides: Vec<BString>,
911 format: OutputFormat,
1012 mut out: impl std::io::Write,
1113 ) -> Result<()> {
1214 if format != OutputFormat::Human {
1315 bail!("Only human output format is supported at the moment");
1416 }
15− let repo = git::open_opts(repo.git_dir(), repo.open_options().clone().lossy_config(false))?;
17+ let mut repo = git::open_opts(repo.git_dir(), repo.open_options().clone().lossy_config(false))?;
18+ repo.config_snapshot_mut().apply_cli_overrides(overrides.into_iter())?;
1619 let config = repo.config_snapshot();
1720 let config = config.plumbing();
1821 if let Some(frontmatter) = config.frontmatter() {
src/plumbing/main.rs+20−14
@@ -62,20 +62,24 @@ pub fn main() -> Result<()> { · 61 unmodified lines
6262 Strict,
6363 Lenient,
6464 }
65− let repository = move |mode: Mode| -> Result<git::Repository> {
66− let mut mapping: git::sec::trust::Mapping<git::open::Options> = Default::default();
67− let toggle = matches!(mode, Mode::Strict);
68− mapping.full = mapping.full.strict_config(toggle);
69− mapping.reduced = mapping.reduced.strict_config(toggle);
70− let mut repo = git::ThreadSafeRepository::discover_opts(repository, Default::default(), mapping)
71− .map(git::Repository::from)
72− .map(|r| r.apply_environment())?;
73− if !config.is_empty() {
74− repo.config_snapshot_mut()
75− .apply_cli_overrides(config)
76− .context("Unable to parse command-line configuration")?;
65+
66+ let repository = {
67+ let config = config.clone();
68+ move |mode: Mode| -> Result<git::Repository> {
69+ let mut mapping: git::sec::trust::Mapping<git::open::Options> = Default::default();
70+ let toggle = matches!(mode, Mode::Strict);
71+ mapping.full = mapping.full.strict_config(toggle);
72+ mapping.reduced = mapping.reduced.strict_config(toggle);
73+ let mut repo = git::ThreadSafeRepository::discover_opts(repository, Default::default(), mapping)
74+ .map(git::Repository::from)
75+ .map(|r| r.apply_environment())?;
76+ if !config.is_empty() {
77+ repo.config_snapshot_mut()
78+ .apply_cli_overrides(config.iter())
79+ .context("Unable to parse command-line configuration")?;
80+ }
81+ Ok(repo)
7782 }
78− Ok(repo)
7983 };
8084
8185 let progress;
@@ -142,7 +146,9 @@ pub fn main() -> Result<()> { · 60 unmodified lines
142146 progress,
143147 progress_keep_open,
144148 None,
145− move |_progress, out, _err| core::repository::config::list(repository(Mode::Lenient)?, filter, format, out),
149+ move |_progress, out, _err| {
150+ core::repository::config::list(repository(Mode::Lenient)?, filter, config, format, out)
151+ },
146152 )
147153 .map(|_| ()),
148154 Subcommands::Free(subcommands) => match subcommands {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t