Skip to content

Commit

Permalink
Select gix commands will now load the git installation configuration (
Browse files Browse the repository at this point in the history
#450)

This is important as it may contain additional credential helper
configuration that we definitely need to find the credentials that
git usually finds.
  • Loading branch information
Byron committed Sep 5, 2022
1 parent d51e7c9 commit 23d2dec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion git-repository/src/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl ReplacementObjects {
pub struct Options {
pub(crate) object_store_slots: git_odb::store::init::Slots,
pub(crate) replacement_objects: ReplacementObjects,
pub(crate) permissions: Permissions,
/// Define what is allowed while openeing a repository.
pub permissions: Permissions,
pub(crate) git_dir_trust: Option<git_sec::Trust>,
/// Warning: this one is copied to to config::Cache - don't change it after repo open or keep in sync.
pub(crate) filter_config_section: Option<fn(&git_config::file::Metadata) -> bool>,
Expand Down
26 changes: 20 additions & 6 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,24 @@ pub fn main() -> Result<()> {
let repository = args.repository;
enum Mode {
Strict,
StrictWithGitInstallConfig,
Lenient,
LenientWithGitInstallConfig,
}

let repository = {
let config = config.clone();
move |mode: Mode| -> Result<git::Repository> {
let mut mapping: git::sec::trust::Mapping<git::open::Options> = Default::default();
let toggle = matches!(mode, Mode::Strict);
mapping.full = mapping.full.strict_config(toggle);
mapping.reduced = mapping.reduced.strict_config(toggle);
let strict_toggle = matches!(mode, Mode::Strict | Mode::StrictWithGitInstallConfig);
mapping.full = mapping.full.strict_config(strict_toggle);
mapping.reduced = mapping.reduced.strict_config(strict_toggle);
let git_installation = matches!(
mode,
Mode::StrictWithGitInstallConfig | Mode::LenientWithGitInstallConfig
);
mapping.full.permissions.config.git_binary = git_installation;
mapping.reduced.permissions.config.git_binary = git_installation;
let mut repo = git::ThreadSafeRepository::discover_opts(repository, Default::default(), mapping)
.map(git::Repository::from)
.map(|r| r.apply_environment())?;
Expand Down Expand Up @@ -103,7 +111,7 @@ pub fn main() -> Result<()> {

match cmd {
Subcommands::Credential(cmd) => core::repository::credential(
repository(Mode::Strict)?,
repository(Mode::StrictWithGitInstallConfig)?,
match cmd {
credential::Subcommands::Fill => git::credentials::program::main::Action::Get,
credential::Subcommands::Approve => git::credentials::program::main::Action::Store,
Expand All @@ -124,7 +132,7 @@ pub fn main() -> Result<()> {
core::repository::remote::refs::PROGRESS_RANGE,
move |progress, out, _err| {
core::repository::remote::refs(
repository(Mode::Lenient)?,
repository(Mode::LenientWithGitInstallConfig)?,
progress,
out,
core::repository::remote::refs::Context { name, url, format },
Expand Down Expand Up @@ -155,7 +163,13 @@ pub fn main() -> Result<()> {
progress_keep_open,
None,
move |_progress, out, _err| {
core::repository::config::list(repository(Mode::Lenient)?, filter, config, format, out)
core::repository::config::list(
repository(Mode::LenientWithGitInstallConfig)?,
filter,
config,
format,
out,
)
},
)
.map(|_| ()),
Expand Down

0 comments on commit 23d2dec

Please sign in to comment.