more accessor functions and better bad url handling
This commit is contained in:
parent
b1caa49248
commit
14bc885de9
1 changed files with 18 additions and 2 deletions
20
GitRepo.hs
20
GitRepo.hs
|
@ -16,11 +16,13 @@ module GitRepo (
|
||||||
repoIsUrl,
|
repoIsUrl,
|
||||||
repoIsSsh,
|
repoIsSsh,
|
||||||
repoDescribe,
|
repoDescribe,
|
||||||
|
repoLocation,
|
||||||
workTree,
|
workTree,
|
||||||
gitDir,
|
gitDir,
|
||||||
relative,
|
relative,
|
||||||
urlPath,
|
urlPath,
|
||||||
urlHost,
|
urlHost,
|
||||||
|
urlScheme,
|
||||||
configGet,
|
configGet,
|
||||||
configMap,
|
configMap,
|
||||||
configRead,
|
configRead,
|
||||||
|
@ -101,7 +103,10 @@ repoFromUrl :: String -> Repo
|
||||||
repoFromUrl url
|
repoFromUrl url
|
||||||
| startswith "file://" url = repoFromPath $ uriPath u
|
| startswith "file://" url = repoFromPath $ uriPath u
|
||||||
| otherwise = newFrom $ Url u
|
| otherwise = newFrom $ Url u
|
||||||
where u = fromJust $ parseURI url
|
where
|
||||||
|
u = case (parseURI url) of
|
||||||
|
Just v -> v
|
||||||
|
Nothing -> error $ "bad url " ++ url
|
||||||
|
|
||||||
{- User-visible description of a git repo. -}
|
{- User-visible description of a git repo. -}
|
||||||
repoDescribe :: Repo -> String
|
repoDescribe :: Repo -> String
|
||||||
|
@ -109,6 +114,11 @@ repoDescribe Repo { remoteName = Just name } = name
|
||||||
repoDescribe Repo { location = Url url } = show url
|
repoDescribe Repo { location = Url url } = show url
|
||||||
repoDescribe Repo { location = Dir dir } = dir
|
repoDescribe Repo { location = Dir dir } = dir
|
||||||
|
|
||||||
|
{- Location of the repo, either as a path or url. -}
|
||||||
|
repoLocation :: Repo -> String
|
||||||
|
repoLocation Repo { location = Url url } = show url
|
||||||
|
repoLocation Repo { location = Dir dir } = dir
|
||||||
|
|
||||||
{- Constructs and returns an updated version of a repo with
|
{- Constructs and returns an updated version of a repo with
|
||||||
- different remotes list. -}
|
- different remotes list. -}
|
||||||
remotesAdd :: Repo -> [Repo] -> Repo
|
remotesAdd :: Repo -> [Repo] -> Repo
|
||||||
|
@ -192,10 +202,16 @@ relative repo@(Repo { location = Dir d }) file = do
|
||||||
Nothing -> error $ file ++ " is not located inside git repository " ++ absrepo
|
Nothing -> error $ file ++ " is not located inside git repository " ++ absrepo
|
||||||
relative repo _ = assertLocal repo $ error "internal"
|
relative repo _ = assertLocal repo $ error "internal"
|
||||||
|
|
||||||
|
{- Scheme of an URL repo. -}
|
||||||
|
urlScheme :: Repo -> String
|
||||||
|
urlScheme Repo { location = Url u } = uriScheme u
|
||||||
|
urlScheme repo = assertUrl repo $ error "internal"
|
||||||
|
|
||||||
{- Hostname of an URL repo. (May include a username and/or port too.) -}
|
{- Hostname of an URL repo. (May include a username and/or port too.) -}
|
||||||
urlHost :: Repo -> String
|
urlHost :: Repo -> String
|
||||||
urlHost Repo { location = Url u } = uriUserInfo a ++ uriRegName a ++ uriPort a
|
urlHost Repo { location = Url u } = uriUserInfo a ++ uriRegName a ++ uriPort a
|
||||||
where a = fromJust $ uriAuthority u
|
where
|
||||||
|
a = fromMaybe (error $ "bad url " ++ show u) (uriAuthority u)
|
||||||
urlHost repo = assertUrl repo $ error "internal"
|
urlHost repo = assertUrl repo $ error "internal"
|
||||||
|
|
||||||
{- Path of an URL repo. -}
|
{- Path of an URL repo. -}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue