1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 17:14:52 +09:00

Implement an 'initRepo' that actually works

This commit is contained in:
fr33domlover 2016-05-02 23:11:32 +00:00
parent d8d2d160a0
commit 0b06b72b85
3 changed files with 91 additions and 4 deletions

81
src/Data/Git/Local.hs Normal file
View file

@ -0,0 +1,81 @@
{- This file is part of Vervis.
-
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
-
- 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
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
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

View file

@ -44,7 +44,7 @@ import Data.Git.Graph
import Data.Git.Harder import Data.Git.Harder
import Data.Git.Named (RefName (..)) import Data.Git.Named (RefName (..))
import Data.Git.Ref (toHex) 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 (withRepo, getObject_)
import Data.Git.Storage.Object (Object (..)) import Data.Git.Storage.Object (Object (..))
import Data.Git.Types (Blob (..), Commit (..), Person (..), entName) 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 qualified Data.Text.Lazy.Encoding as L (decodeUtf8With)
import Data.ByteString.Char8.Local (takeLine) import Data.ByteString.Char8.Local (takeLine)
import Data.Git.Local (initRepo)
import Text.FilePath.Local (breakExt) import Text.FilePath.Local (breakExt)
import Vervis.Form.Repo import Vervis.Form.Repo
import Vervis.Foundation import Vervis.Foundation
@ -97,9 +98,9 @@ postReposR user = do
case result of case result of
FormSuccess repo -> do FormSuccess repo -> do
parent <- askSharerDir user parent <- askSharerDir user
let path = parent </> unpack (repoIdent repo) liftIO $ do
liftIO $ createDirectoryIfMissing True parent createDirectoryIfMissing True parent
liftIO $ initRepo $ fromString path initRepo parent (unpack $ repoIdent repo)
runDB $ insert_ repo runDB $ insert_ repo
setMessage "Repo added." setMessage "Repo added."
redirectUltDest HomeR redirectUltDest HomeR

View file

@ -38,6 +38,7 @@ library
Data.ByteString.Char8.Local Data.ByteString.Char8.Local
Data.ByteString.Local Data.ByteString.Local
Data.Char.Local Data.Char.Local
Data.Git.Local
Data.List.Local Data.List.Local
Network.SSH.Local Network.SSH.Local
Text.FilePath.Local Text.FilePath.Local
@ -109,6 +110,8 @@ library
, containers , containers
, data-default , data-default
, directory , directory
-- for Data.Git.Local
, directory-tree
, dlist , dlist
, esqueleto , esqueleto
, fast-logger , fast-logger
@ -117,7 +120,9 @@ library
, filepath , filepath
, formatting , formatting
, hashable , hashable
-- for source file highlighting
, highlighter2 , highlighter2
-- for pandoc inline code highlighting
, highlighting-kate , highlighting-kate
, hit , hit
, hit-graph >= 0.1 , hit-graph >= 0.1