Skip to content

Commit

Permalink
feat: add gitoxide.core.externalCommandStderr to allow enabling `st…
Browse files Browse the repository at this point in the history
…derr` to the enclosing terminal.

Previously, this was enabled by default, now it can additionally be disabled by
the caller.
  • Loading branch information
Byron committed Dec 6, 2023
1 parent ceb8826 commit 2762724
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions gix/src/config/cache/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ fn apply_environment_overrides(
let key = &gitoxide::Core::REFS_NAMESPACE;
(env(key), key.name)
},
{
let key = &gitoxide::Core::EXTERNAL_COMMAND_STDERR;
(env(key), key.name)
},
],
),
(
Expand Down
10 changes: 10 additions & 0 deletions gix/src/config/tree/sections/gitoxide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ mod subsections {
pub const FILTER_PROCESS_DELAY: keys::Boolean =
keys::Boolean::new_boolean("filterProcessDelay", &Gitoxide::CORE);

/// The `gitoxide.core.externalCommandStderr` key (default `true`).
///
/// If `true`, the default, `stderr` of worktree filter programs, or any other git-context bearing command
/// invoked will be inherited.
/// If `false`, it will be suppressed completely.
pub const EXTERNAL_COMMAND_STDERR: keys::Boolean =
keys::Boolean::new_boolean("externalCommandStderr", &Gitoxide::CORE)
.with_environment_override("GIX_EXTERNAL_COMMAND_STDERR");

/// The `gitoxide.core.refsNamespace` key.
pub const REFS_NAMESPACE: RefsNamespace =
keys::Any::new_with_validate("refsNamespace", &Gitoxide::CORE, super::validate::RefsNamespace)
Expand All @@ -134,6 +143,7 @@ mod subsections {
&Self::USE_STDEV,
&Self::SHALLOW_FILE,
&Self::FILTER_PROCESS_DELAY,
&Self::EXTERNAL_COMMAND_STDERR,
&Self::REFS_NAMESPACE,
]
}
Expand Down
21 changes: 17 additions & 4 deletions gix/src/repository/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,27 @@ impl crate::Repository {
tree::{gitoxide, Key},
};

let boolean = |key: &dyn Key| {
let pathspec_boolean = |key: &'static config::tree::keys::Boolean| {
self.config
.resolved
.boolean("gitoxide", Some("pathspec".into()), key.name())
.map(|value| key.enrich_error(value))
.transpose()
.with_leniency(self.config.lenient_config)
};

Ok(gix_command::Context {
stderr: {
let key = &gitoxide::Core::EXTERNAL_COMMAND_STDERR;
self.config
.resolved
.boolean("gitoxide", Some("core".into()), key.name())
.map(|value| key.enrich_error(value))
.transpose()
.with_leniency(self.config.lenient_config)?
.unwrap_or(true)
.into()
},
git_dir: self.git_dir().to_owned().into(),
worktree_dir: self.work_dir().map(ToOwned::to_owned),
no_replace_objects: config::shared::is_replace_refs_enabled(
Expand All @@ -106,9 +118,10 @@ impl crate::Repository {
)?
.map(|enabled| !enabled),
ref_namespace: self.refs.namespace.as_ref().map(|ns| ns.as_bstr().to_owned()),
literal_pathspecs: boolean(&gitoxide::Pathspec::LITERAL)?,
glob_pathspecs: boolean(&gitoxide::Pathspec::GLOB)?.or(boolean(&gitoxide::Pathspec::NOGLOB)?),
icase_pathspecs: boolean(&gitoxide::Pathspec::ICASE)?,
literal_pathspecs: pathspec_boolean(&gitoxide::Pathspec::LITERAL)?,
glob_pathspecs: pathspec_boolean(&gitoxide::Pathspec::GLOB)?
.or(pathspec_boolean(&gitoxide::Pathspec::NOGLOB)?),
icase_pathspecs: pathspec_boolean(&gitoxide::Pathspec::ICASE)?,
})
}

Expand Down
2 changes: 2 additions & 0 deletions gix/tests/gix-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod with_overrides {
.set("GIX_PACK_CACHE_MEMORY", "0")
.set("GIX_OBJECT_CACHE_MEMORY", "5m")
.set("GIX_CREDENTIALS_HELPER_STDERR", "creds-stderr")
.set("GIX_EXTERNAL_COMMAND_STDERR", "filter-stderr")
.set("GIT_SSL_CAINFO", "./env.pem")
.set("GIT_SSL_VERSION", "tlsv1.3")
.set("GIT_SSH_VARIANT", "ssh-variant-env")
Expand Down Expand Up @@ -256,6 +257,7 @@ mod with_overrides {
("gitoxide.pathspec.literal", "pathspecs-literal"),
("gitoxide.credentials.terminalPrompt", "42"),
("gitoxide.credentials.helperStderr", "creds-stderr"),
("gitoxide.core.externalCommandStderr", "filter-stderr"),
] {
assert_eq!(
config
Expand Down

0 comments on commit 2762724

Please sign in to comment.