diff --git a/git-ref/src/lib.rs b/git-ref/src/lib.rs index f202fc913b..9c26defa2e 100644 --- a/git-ref/src/lib.rs +++ b/git-ref/src/lib.rs @@ -28,6 +28,8 @@ pub mod mutable; /// pub mod name; /// +pub mod namespace; +/// pub mod transaction; /// A validated and potentially partial reference name - it can safely be used for common operations. diff --git a/git-ref/src/name.rs b/git-ref/src/name.rs index 45588bd657..e859f43692 100644 --- a/git-ref/src/name.rs +++ b/git-ref/src/name.rs @@ -9,6 +9,7 @@ mod error { quick_error! { /// The error used in the [`PartialName`][super::PartialName]::try_from(…) implementations. + /// TODO: remove this error, turning it into the inner one. This is an unnecessary proxy #[derive(Debug)] #[allow(missing_docs)] pub enum Error { diff --git a/git-ref/src/namespace.rs b/git-ref/src/namespace.rs new file mode 100644 index 0000000000..63f30204c4 --- /dev/null +++ b/git-ref/src/namespace.rs @@ -0,0 +1,35 @@ +#![allow(missing_docs)] + +use crate::PartialName; +use std::convert::TryInto; + +pub fn expand<'a, Name, E>(namespace: Name) -> Result +where + Name: TryInto, Error = E>, + expand::Error: From, +{ + let _namespace = namespace.try_into()?; + todo!("impl") +} + +pub mod expand { + use quick_error::quick_error; + use std::convert::Infallible; + + quick_error! { + #[derive(Debug)] + pub enum Error { + RefnameValidation(err: crate::name::Error) { + display("The ref name or path is not a valid ref name") + from() + source(err) + } + } + } + + impl From for Error { + fn from(_: Infallible) -> Self { + unreachable!("this impl is needed to allow passing a known valid partial path as parameter") + } + } +} diff --git a/git-ref/tests/namespace/mod.rs b/git-ref/tests/namespace/mod.rs new file mode 100644 index 0000000000..50380446f9 --- /dev/null +++ b/git-ref/tests/namespace/mod.rs @@ -0,0 +1,28 @@ +mod expand { + #[test] + fn each_component_expands_to_the_namespace_prefix_individually() { + assert_eq!( + git_ref::namespace::expand("foo/bar").unwrap().as_bstr(), + "refs/namespaces/foo/refs/namespaces/bar/" + ) + } + + #[test] + #[ignore] + fn only_backslashes_are_valid_component_separators() {} + + #[test] + #[ignore] + fn trailing_slashes_do_nothing() {} + + #[test] + fn empty_namespaces_are_not_allowed() { + assert!(matches!( + git_ref::namespace::expand("").expect_err("empty invalid"), + git_ref::namespace::expand::Error::RefnameValidation(git_ref::name::Error::RefnameValidation { + err: git_validate::refname::Error::Tag(git_validate::tag::name::Error::Empty), + .. + }) + )) + } +} diff --git a/git-ref/tests/refs-parallel.rs b/git-ref/tests/refs-parallel.rs index ec9104928d..f6e7421a80 100644 --- a/git-ref/tests/refs-parallel.rs +++ b/git-ref/tests/refs-parallel.rs @@ -1,5 +1,6 @@ type Result = std::result::Result>; mod file; +mod namespace; mod packed; mod transaction; diff --git a/git-ref/tests/refs.rs b/git-ref/tests/refs.rs index ec9104928d..f6e7421a80 100644 --- a/git-ref/tests/refs.rs +++ b/git-ref/tests/refs.rs @@ -1,5 +1,6 @@ type Result = std::result::Result>; mod file; +mod namespace; mod packed; mod transaction;