gix 0.86.0

Interact with git repositories just like git would
Documentation
use crate::{
    config,
    config::tree::{Key, Push, Section, keys},
};

impl Push {
    /// The `push.default` key
    pub const DEFAULT: Default = Default::new_with_validate("default", &config::Tree::PUSH, validate::Default);
}

impl Section for Push {
    fn name(&self) -> &str {
        "push"
    }

    fn keys(&self) -> &[&dyn Key] {
        &[&Self::DEFAULT]
    }
}

/// The `remote.<name>.tagOpt` key type.
pub type Default = keys::Any<validate::Default>;

mod default {
    use crate::{bstr::ByteSlice, config, config::tree::push::Default, push};

    impl Default {
        /// Try to interpret `value` as `push.default`.
        pub fn try_into_default(
            &'static self,
            value: impl gix_utils::AsBStr,
        ) -> Result<push::Default, config::key::GenericErrorWithValue> {
            let value = value.as_bstr();
            Ok(match value.as_bstr().as_bytes() {
                b"nothing" => push::Default::Nothing,
                b"current" => push::Default::Current,
                b"upstream" | b"tracking" => push::Default::Upstream,
                b"simple" => push::Default::Simple,
                b"matching" => push::Default::Matching,
                _ => return Err(config::key::GenericErrorWithValue::from_value(self, value.into())),
            })
        }
    }
}

mod validate {
    #[derive(Clone, Copy)]
    pub struct Default;
    use std::error::Error;

    use crate::{bstr::BStr, config::tree::keys::Validate};

    impl Validate for Default {
        fn validate(&self, value: &BStr) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
            super::Push::DEFAULT.try_into_default(value)?;
            Ok(())
        }
    }
}