{-# LANGUAGE FlexibleContexts #-}
-- | Performing git operations with a repository. Does so by calling git on
-- command line.
--
-- A git repository needs to be bare for pushes to work, so it can't be the
-- same repository human uses.
--
-- Git pull happens in two steps, both handled by the same command @git
-- upload-pack --stateless-rpc .@. On the first step a request comes to
-- @info/refs@ to which you respond with the output of this command with
-- appended `--advertise-refs`. On the second step a request comes to
-- @git-upload-pack@, where you need to read the request body and supply it to
-- the command.
--
-- Git push is similar, with the command @git receive-pack --stateless-rpc .@
-- with the same flag and behaviour, with routes @info/refs@ and
-- @git-receive-pack@. On advertisement you also need to prepend a git packet
-- with the service name, as git cmdline doesn't do it.
--
-- In all cases you need to read git version header from the http request and
-- set it verbatim as env variable @GIT_PROTOCOL@.
--
-- You can distinguish advertise-refs between pull and push by a query
-- parameter set to the receive or upload
--
-- Implementation taken from https://github.com/asim/git-http-backend - they
-- also have other routes there, for which I haven't found use yet.
module Git
( -- ** Types
GitImpl (..)
, GitObject (..)
, HistoryItem (..)
-- ** Creation
, make
) where
import ClassyPrelude hiding (hash, stderr, stdin, stdout)
import qualified Git.Cached as Cached
import qualified Git.CommandLine as CommandLine
import Git.Class (GitImpl (..), GitObject (..), HistoryItem (..))
import System.OsPath (OsPath)
make :: Int -> OsPath -> IO GitImpl
make clearDelay = Cached.make clearDelay . CommandLine.make