From 339c2253f97bc611307cd1d49985b837ceaaab1d Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sat, 19 Oct 2019 06:01:14 +0000 Subject: [PATCH] If Git repo is empty (no branches), don't 404, just show basic repo page --- src/Vervis/Git.hs | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Vervis/Git.hs b/src/Vervis/Git.hs index c3930f7..db30030 100644 --- a/src/Vervis/Git.hs +++ b/src/Vervis/Git.hs @@ -119,29 +119,30 @@ loadSourceView git refT dir = do tags <- G.tagList git let refS = T.unpack refT refN = RefName refS - msv <- if refN `S.member` branches || refN `S.member` tags - then do - tipOid <- resolveName git refS - mtree <- G.resolveTreeish git $ unObjId tipOid - case mtree of - Nothing -> return Nothing - Just tree -> do - let dir' = map (G.entName . encodeUtf8) dir - view <- viewPath git tree dir' - Just <$> case view of - RootView rows -> do - mreadme <- findReadme git rows - let ents = map rowToEntry rows - return $ SourceDir $ - DirectoryView Nothing ents mreadme - TreeView name _ rows -> do - mreadme <- findReadme git rows - let ents = map rowToEntry rows - return $ SourceDir $ - DirectoryView (Just name) ents mreadme - BlobView name _ body -> - return $ SourceFile $ FileView name body - else return Nothing + msv <- + if null branches + then return $ Just $ SourceDir $ DirectoryView Nothing [] Nothing + else if refN `S.member` branches || refN `S.member` tags + then do + tipOid <- resolveName git refS + mtree <- G.resolveTreeish git $ unObjId tipOid + for mtree $ \ tree -> do + let dir' = map (G.entName . encodeUtf8) dir + view <- viewPath git tree dir' + case view of + RootView rows -> do + mreadme <- findReadme git rows + let ents = map rowToEntry rows + return $ SourceDir $ + DirectoryView Nothing ents mreadme + TreeView name _ rows -> do + mreadme <- findReadme git rows + let ents = map rowToEntry rows + return $ SourceDir $ + DirectoryView (Just name) ents mreadme + BlobView name _ body -> + return $ SourceFile $ FileView name body + else return Nothing return (branches, tags, msv) readSourceView