Skip to content

Commit

Permalink
fix; SnapshotMut::set_value() now sets values for keys in subsectio…
Browse files Browse the repository at this point in the history
…ns as well (#1125).
  • Loading branch information
Byron committed Nov 24, 2023
1 parent f291437 commit 4fb8486
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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
21 changes: 20 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,25 @@ 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.
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

0 comments on commit 4fb8486

Please sign in to comment.