git_atomic/config/
git_provider.rs1use figment::value::{Dict, Map};
2use figment::{Error, Metadata, Profile, Provider};
3
4pub struct GitConfigProvider {
10 settings: Dict,
11}
12
13impl GitConfigProvider {
14 pub fn new(repo: Option<&gix::Repository>) -> Self {
16 let mut settings = Dict::new();
17 if let Some(repo) = repo {
18 let snapshot = repo.config_snapshot();
19
20 if let Some(v) = snapshot.string_by("atomic", None, "baseBranch") {
21 settings.insert("base_branch".into(), v.to_string().into());
22 }
23 if let Some(v) = snapshot.string_by("atomic", None, "branchTemplate") {
24 settings.insert("branch_template".into(), v.to_string().into());
25 }
26 if let Some(v) = snapshot.string_by("atomic", None, "unmatchedFiles") {
27 settings.insert("unmatched_files".into(), v.to_string().into());
28 }
29 if let Some(v) = snapshot.string_by("atomic", None, "defaultCommitType") {
30 settings.insert("default_commit_type".into(), v.to_string().into());
31 }
32 }
33 Self { settings }
34 }
35}
36
37impl Provider for GitConfigProvider {
38 fn metadata(&self) -> Metadata {
39 Metadata::named("git config")
40 }
41
42 fn data(&self) -> Result<Map<Profile, Dict>, Error> {
43 let mut inner = Dict::new();
45 if !self.settings.is_empty() {
46 inner.insert("settings".into(), self.settings.clone().into());
47 }
48 Ok(Profile::Default.collect(inner))
49 }
50}