Skip to content

improve usability of configuration access #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions gix/src/config/snapshot/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ impl<'repo> SnapshotMut<'repo> {
}
let value = new_value.into();
key.validate(value)?;
let current = self
.config
.set_raw_value(key.section().name(), None, key.name(), value)?;
let section = key.section();
let current = match section.parent() {
Some(parent) => self
.config
.set_raw_value(parent.name(), Some(section.name().into()), key.name(), value)?,
None => self.config.set_raw_value(section.name(), None, key.name(), value)?,
};
Ok(current.map(std::borrow::Cow::into_owned))
}

Expand Down
23 changes: 22 additions & 1 deletion gix/tests/repository/config/config_snapshot/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gix::config::tree::{Branch, Core, Key};
use gix::config::tree::{gitoxide, Branch, Core, Key};

use crate::named_repo;

Expand Down Expand Up @@ -91,6 +91,27 @@ fn values_are_set_in_memory_only() {
assert_eq!(repo_clone.config_snapshot().string(key_subsection), None);
}

#[test]
fn set_value_in_subsection() {
let mut repo = named_repo("make_config_repo.sh").unwrap();
{
let mut config = repo.config_snapshot_mut();
config
.set_value(&gitoxide::Credentials::TERMINAL_PROMPT, "yes")
.unwrap();
// TODO: this should probably be symmetric then and take a key. Figure out how non-keyed access would then be possible.
// Maybe there could be different SnapshotMut types? Maybe there could be a prefix for methods for better separation?
// Maybe a sub-type?
assert_eq!(
config
.string_by_key(&*gitoxide::Credentials::TERMINAL_PROMPT.logical_name())
.expect("just set")
.as_ref(),
"yes"
);
}
}

#[test]
fn apply_cli_overrides() -> crate::Result {
let mut repo = named_repo("make_config_repo.sh").unwrap();
Expand Down
4 changes: 2 additions & 2 deletions gix/tests/repository/pathspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ fn defaults_are_taken_from_repo_config() -> crate::Result {
.expect("match")
.is_excluded());

assert_eq!(
assert!(
pathspec.is_included("HI", Some(false)),
repo.filesystem_options()?.ignore_case
"icase is enabled, so filesystem doesn't matter"
);
Ok(())
}