    module Hpack.Syntax.Git (
      isValidRef
    ) where

    import           Data.Char (chr)
    import           Data.List
    import           System.FilePath.Posix

    -- https://git-scm.com/docs/git-check-ref-format
    isValidRef :: String -> Bool
    isValidRef :: String -> Bool
    isValidRef ref :: String
    ref =
         Bool -> Bool
    not (String -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null String
    ref)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ((String -> Bool) -> [String] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any (String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    isSuffixOf ".lock") [String]
    components)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ((String -> Bool) -> [String] -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any (String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    isPrefixOf ".") [String]
    components)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not (".." String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isInfixOf` String
    ref)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ((Char -> Bool) -> String -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    any Char -> Bool
    isControl String
    ref)
      Bool -> Bool -> Bool
    && (Char -> Bool) -> String -> Bool
    forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
    all (Char -> String -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `notElem` " ~^:?*[\\") String
    ref
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ("//" String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isInfixOf` String
    ref)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ("/" String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isPrefixOf` String
    ref)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ("/" String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isSuffixOf` String
    ref)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ("." String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isSuffixOf` String
    ref)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not ("@{" String -> String -> Bool
    forall a. Eq a => [a] -> [a] -> Bool
    `isInfixOf` String
    ref)
      Bool -> Bool -> Bool
    && Bool -> Bool
    not (String
    ref String -> String -> Bool
    forall a. Eq a => a -> a -> Bool
    == "@")
      where
        components :: [String]
    components = String -> [String]
    splitDirectories String
    ref

    isControl :: Char -> Bool
    isControl :: Char -> Bool
    isControl c :: Char
    c = Char
    c Char -> Char -> Bool
    forall a. Ord a => a -> a -> Bool
    < Int -> Char
    chr 0o040 Bool -> Bool -> Bool
    || Char
    c Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    == Int -> Char
    chr 0o177