gix/config/tree/
mod.rs

1//! The tree of supported configuration values for use in [`config_overrides`][crate::open::Options::config_overrides()]
2//! or for validating and transforming well-known configuration values.
3//!
4//! It can also be used to traverse all implemented keys and to validate values before usage as configuration overrides.
5//!
6//! ### Leniency
7//!
8//! When validating values, we don't apply leniency here which is left to the caller. Leniency is an application defined configuration
9//! to ignore errors on non-security related values, which might make applications more resilient towards misconfiguration.
10pub(crate) mod root {
11    use super::sections;
12    use crate::config::tree::Section;
13
14    /// The root of the configuration tree, suitable to discover all sub-sections at runtime or compile time.
15    #[derive(Copy, Clone, Default)]
16    pub struct Tree;
17
18    impl Tree {
19        /// The `author` section.
20        pub const AUTHOR: sections::Author = sections::Author;
21        /// The `branch` section.
22        pub const BRANCH: sections::Branch = sections::Branch;
23        /// The `checkout` section.
24        pub const CHECKOUT: sections::Checkout = sections::Checkout;
25        /// The `clone` section.
26        pub const CLONE: sections::Clone = sections::Clone;
27        /// The `committer` section.
28        pub const COMMITTER: sections::Committer = sections::Committer;
29        /// The `core` section.
30        pub const CORE: sections::Core = sections::Core;
31        /// The `credential` section.
32        pub const CREDENTIAL: sections::Credential = sections::Credential;
33        /// The `diff` section.
34        #[cfg(feature = "blob-diff")]
35        pub const DIFF: sections::Diff = sections::Diff;
36        /// The `extensions` section.
37        pub const EXTENSIONS: sections::Extensions = sections::Extensions;
38        /// The `fetch` section.
39        pub const FETCH: sections::Fetch = sections::Fetch;
40        /// The `gitoxide` section.
41        pub const GITOXIDE: sections::Gitoxide = sections::Gitoxide;
42        /// The `http` section.
43        pub const HTTP: sections::Http = sections::Http;
44        /// The `index` section.
45        pub const INDEX: sections::Index = sections::Index;
46        /// The `init` section.
47        pub const INIT: sections::Init = sections::Init;
48        /// The `mailmap` section.
49        pub const MAILMAP: sections::Mailmap = sections::Mailmap;
50        /// The `merge` section.
51        pub const MERGE: sections::Merge = sections::Merge;
52        /// The `pack` section.
53        pub const PACK: sections::Pack = sections::Pack;
54        /// The `protocol` section.
55        pub const PROTOCOL: sections::Protocol = sections::Protocol;
56        /// The `push` section.
57        pub const PUSH: sections::Push = sections::Push;
58        /// The `remote` section.
59        pub const REMOTE: sections::Remote = sections::Remote;
60        /// The `safe` section.
61        pub const SAFE: sections::Safe = sections::Safe;
62        /// The `ssh` section.
63        pub const SSH: sections::Ssh = sections::Ssh;
64        /// The `status` section.
65        #[cfg(feature = "status")]
66        pub const STATUS: sections::Status = sections::Status;
67        /// The `user` section.
68        pub const USER: sections::User = sections::User;
69        /// The `url` section.
70        pub const URL: sections::Url = sections::Url;
71
72        /// List all available sections.
73        pub fn sections(&self) -> &[&dyn Section] {
74            &[
75                &Self::AUTHOR,
76                &Self::BRANCH,
77                &Self::CHECKOUT,
78                &Self::CLONE,
79                &Self::COMMITTER,
80                &Self::CORE,
81                &Self::CREDENTIAL,
82                #[cfg(feature = "blob-diff")]
83                &Self::DIFF,
84                &Self::EXTENSIONS,
85                &Self::FETCH,
86                &Self::GITOXIDE,
87                &Self::HTTP,
88                &Self::INDEX,
89                &Self::INIT,
90                &Self::MAILMAP,
91                &Self::MERGE,
92                &Self::PACK,
93                &Self::PROTOCOL,
94                &Self::PUSH,
95                &Self::REMOTE,
96                &Self::SAFE,
97                &Self::SSH,
98                #[cfg(feature = "status")]
99                &Self::STATUS,
100                &Self::USER,
101                &Self::URL,
102            ]
103        }
104    }
105}
106
107mod sections;
108pub use sections::{
109    branch, checkout, core, credential, extensions, fetch, gitoxide, http, index, protocol, push, remote, ssh, Author,
110    Branch, Checkout, Clone, Committer, Core, Credential, Extensions, Fetch, Gitoxide, Http, Index, Init, Mailmap,
111    Merge, Pack, Protocol, Push, Remote, Safe, Ssh, Url, User,
112};
113#[cfg(feature = "blob-diff")]
114pub use sections::{diff, Diff};
115#[cfg(feature = "status")]
116pub use sections::{status, Status};
117
118/// Generic value implementations for static instantiation.
119pub mod keys;
120
121///
122pub mod key {
123    ///
124    pub mod validate {
125        /// The error returned by [`Key::validate()`][crate::config::tree::Key::validate()].
126        #[derive(Debug, thiserror::Error)]
127        #[error(transparent)]
128        #[allow(missing_docs)]
129        pub struct Error {
130            #[from]
131            source: Box<dyn std::error::Error + Send + Sync + 'static>,
132        }
133    }
134    ///
135    pub mod validate_assignment {
136        /// The error returned by [`Key::validated_assignment`*()][crate::config::tree::Key::validated_assignment_fmt()].
137        #[derive(Debug, thiserror::Error)]
138        #[allow(missing_docs)]
139        pub enum Error {
140            #[error("Failed to validate the value to be assigned to this key")]
141            Validate(#[from] super::validate::Error),
142            #[error("{message}")]
143            Name { message: String },
144        }
145    }
146}
147
148mod traits;
149pub use traits::{Key, Link, Note, Section, SubSectionRequirement};