Skip to content

Commit 4fb8486

Browse files
committed
fix; SnapshotMut::set_value() now sets values for keys in subsections as well (#1125).
1 parent f291437 commit 4fb8486

File tree

2 files changed

+27
-4
lines changed
  • gix

2 files changed

+27
-4
lines changed

gix/src/config/snapshot/access.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ impl<'repo> SnapshotMut<'repo> {
118118
}
119119
let value = new_value.into();
120120
key.validate(value)?;
121-
let current = self
122-
.config
123-
.set_raw_value(key.section().name(), None, key.name(), value)?;
121+
let section = key.section();
122+
let current = match section.parent() {
123+
Some(parent) => self
124+
.config
125+
.set_raw_value(parent.name(), Some(section.name().into()), key.name(), value)?,
126+
None => self.config.set_raw_value(section.name(), None, key.name(), value)?,
127+
};
124128
Ok(current.map(std::borrow::Cow::into_owned))
125129
}
126130

gix/tests/repository/config/config_snapshot/mod.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use gix::config::tree::{Branch, Core, Key};
1+
use gix::config::tree::{gitoxide, Branch, Core, Key};
22

33
use crate::named_repo;
44

@@ -91,6 +91,25 @@ fn values_are_set_in_memory_only() {
9191
assert_eq!(repo_clone.config_snapshot().string(key_subsection), None);
9292
}
9393

94+
#[test]
95+
fn set_value_in_subsection() {
96+
let mut repo = named_repo("make_config_repo.sh").unwrap();
97+
{
98+
let mut config = repo.config_snapshot_mut();
99+
config
100+
.set_value(&gitoxide::Credentials::TERMINAL_PROMPT, "yes")
101+
.unwrap();
102+
// TODO: this should probably be symmetric then and take a key. Figure out how non-keyed access would then be possible.
103+
assert_eq!(
104+
config
105+
.string_by_key(&*gitoxide::Credentials::TERMINAL_PROMPT.logical_name())
106+
.expect("just set")
107+
.as_ref(),
108+
"yes"
109+
);
110+
}
111+
}
112+
94113
#[test]
95114
fn apply_cli_overrides() -> crate::Result {
96115
let mut repo = named_repo("make_config_repo.sh").unwrap();

0 commit comments

Comments
 (0)