added a git ref legality checker
git-check-ref-format is .. wow. Good design on one level, but what a mess.
This commit is contained in:
parent
028972c80f
commit
0be6ebb0aa
1 changed files with 23 additions and 0 deletions
23
Git/Ref.hs
23
Git/Ref.hs
|
@ -11,6 +11,8 @@ import Common
|
||||||
import Git
|
import Git
|
||||||
import Git.Command
|
import Git.Command
|
||||||
|
|
||||||
|
import Data.Char (chr)
|
||||||
|
|
||||||
{- Converts a fully qualified git ref into a user-visible string. -}
|
{- Converts a fully qualified git ref into a user-visible string. -}
|
||||||
describe :: Ref -> String
|
describe :: Ref -> String
|
||||||
describe = show . base
|
describe = show . base
|
||||||
|
@ -61,3 +63,24 @@ matchingUniq :: Ref -> Repo -> IO [(Ref, Branch)]
|
||||||
matchingUniq ref repo = nubBy uniqref <$> matching ref repo
|
matchingUniq ref repo = nubBy uniqref <$> matching ref repo
|
||||||
where
|
where
|
||||||
uniqref (a, _) (b, _) = a == b
|
uniqref (a, _) (b, _) = a == b
|
||||||
|
|
||||||
|
{- Checks if a String is a legal git ref name.
|
||||||
|
-
|
||||||
|
- The rules for this are complex; see git-check-ref-format(1) -}
|
||||||
|
legalRef :: Bool -> String -> Bool
|
||||||
|
legalRef allowonelevel s
|
||||||
|
| any ("." `isPrefixOf`) pathbits = False
|
||||||
|
| any (".lock" `isSuffixOf`) pathbits = False
|
||||||
|
| not allowonelevel && length pathbits < 2 = False
|
||||||
|
| ".." `isInfixOf` s = False
|
||||||
|
| any (\c -> [c] `isInfixOf` s) illegalchars = False
|
||||||
|
| "/" `isPrefixOf` s = False
|
||||||
|
| "/" `isSuffixOf` s = False
|
||||||
|
| "//" `isInfixOf` s = False
|
||||||
|
| "." `isSuffixOf` s = False
|
||||||
|
| "@{" `isInfixOf` s = False
|
||||||
|
| otherwise = True
|
||||||
|
where
|
||||||
|
pathbits = split "/" s
|
||||||
|
illegalchars = " ~^:?*[\\" ++ controlchars
|
||||||
|
controlchars = chr 0o177 : [chr 0 .. chr (0o40-1)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue