diff --git a/src/Data/Git/Local.hs b/src/Data/Git/Local.hs new file mode 100644 index 0000000..c103518 --- /dev/null +++ b/src/Data/Git/Local.hs @@ -0,0 +1,81 @@ +{- This file is part of Vervis. + - + - Written in 2016 by fr33domlover . + - + - ♡ Copying is an act of love. Please copy, reuse and share. + - + - The author(s) have dedicated all copyright and related and neighboring + - rights to this software to the public domain worldwide. This software is + - distributed without any warranty. + - + - You should have received a copy of the CC0 Public Domain Dedication along + - with this software. If not, see + - . + -} + +module Data.Git.Local + ( initRepo + ) +where + +import Prelude + +import Control.Monad (when) +import System.Directory.Tree + +import qualified Data.ByteString as B (ByteString, writeFile) + +initialConfig :: B.ByteString +initialConfig = + "[core]\n\ + \ repositoryformatversion = 0\n\ + \ filemode = true\n\ + \ bare = true" + +initialDescription :: B.ByteString +initialDescription = + "Unnamed repository; edit this file to name the repository." + +initialHead :: B.ByteString +initialHead = "ref: refs/heads/master" + +initialExclude :: B.ByteString +initialExclude = "" + +initialRepoTree :: FileName -> DirTree B.ByteString +initialRepoTree repo = + Dir repo + [ Dir "branches" [] + , File "config" initialConfig + , File "description" initialDescription + , File "HEAD" initialHead + , Dir "hooks" [] + , Dir "info" + [ File "exclude" initialExclude + ] + , Dir "objects" + [ Dir "info" [] + , Dir "pack" [] + ] + , Dir "refs" + [ Dir "heads" [] + , Dir "tags" [] + ] + ] + +-- | initialize a new bare repository at a specific location. +-- +-- Currently in the @hit@ package, i.e. version 0.6.3, the initRepo function +-- creates a directory which the git executable doesn't recognize as a git +-- repository. The version here creates a properly initialized repo. +initRepo + :: FilePath + -- ^ Parent directory which already exists + -> String + -- ^ Name of new repo, i.e. new directory to create under the parent + -> IO () +initRepo path name = do + let tree = path :/ initialRepoTree name + result <- writeDirectoryWith B.writeFile tree + let errs = failures $ dirTree result + when (not . null $ errs) $ error $ show errs diff --git a/src/Vervis/Handler/Repo.hs b/src/Vervis/Handler/Repo.hs index 35eda19..65fed81 100644 --- a/src/Vervis/Handler/Repo.hs +++ b/src/Vervis/Handler/Repo.hs @@ -44,7 +44,7 @@ import Data.Git.Graph import Data.Git.Harder import Data.Git.Named (RefName (..)) import Data.Git.Ref (toHex) -import Data.Git.Repository +import Data.Git.Repository hiding (initRepo) import Data.Git.Storage (withRepo, getObject_) import Data.Git.Storage.Object (Object (..)) import Data.Git.Types (Blob (..), Commit (..), Person (..), entName) @@ -64,6 +64,7 @@ import qualified Data.Set as S (member) import qualified Data.Text.Lazy.Encoding as L (decodeUtf8With) import Data.ByteString.Char8.Local (takeLine) +import Data.Git.Local (initRepo) import Text.FilePath.Local (breakExt) import Vervis.Form.Repo import Vervis.Foundation @@ -97,9 +98,9 @@ postReposR user = do case result of FormSuccess repo -> do parent <- askSharerDir user - let path = parent unpack (repoIdent repo) - liftIO $ createDirectoryIfMissing True parent - liftIO $ initRepo $ fromString path + liftIO $ do + createDirectoryIfMissing True parent + initRepo parent (unpack $ repoIdent repo) runDB $ insert_ repo setMessage "Repo added." redirectUltDest HomeR diff --git a/vervis.cabal b/vervis.cabal index 7f624c1..2e27c45 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -38,6 +38,7 @@ library Data.ByteString.Char8.Local Data.ByteString.Local Data.Char.Local + Data.Git.Local Data.List.Local Network.SSH.Local Text.FilePath.Local @@ -109,6 +110,8 @@ library , containers , data-default , directory + -- for Data.Git.Local + , directory-tree , dlist , esqueleto , fast-logger @@ -117,7 +120,9 @@ library , filepath , formatting , hashable + -- for source file highlighting , highlighter2 + -- for pandoc inline code highlighting , highlighting-kate , hit , hit-graph >= 0.1