2019-08-26 16:32:45 +00:00
|
|
|
{- making local repositories
|
2014-06-16 22:59:23 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012-2014 Joey Hess <id@joeyh.name>
|
2014-06-16 22:59:23 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-06-16 22:59:23 +00:00
|
|
|
-}
|
|
|
|
|
2019-08-26 16:32:45 +00:00
|
|
|
module Assistant.MakeRepo where
|
2014-06-16 22:59:23 +00:00
|
|
|
|
|
|
|
import Assistant.WebApp.Common
|
|
|
|
import Annex.Init
|
|
|
|
import qualified Git.Construct
|
|
|
|
import qualified Git.Config
|
|
|
|
import qualified Git.Command
|
2014-07-04 15:36:59 +00:00
|
|
|
import qualified Git.Branch
|
2014-06-16 22:59:23 +00:00
|
|
|
import qualified Annex
|
|
|
|
import Annex.UUID
|
2019-08-26 16:53:56 +00:00
|
|
|
import Annex.AdjustedBranch
|
2017-09-30 02:36:08 +00:00
|
|
|
import Annex.Action
|
2014-06-16 22:59:23 +00:00
|
|
|
import Types.StandardGroups
|
|
|
|
import Logs.PreferredContent
|
|
|
|
import qualified Annex.Branch
|
2017-12-31 20:08:31 +00:00
|
|
|
import Utility.Process.Transcript
|
2019-08-26 16:53:56 +00:00
|
|
|
import Config
|
2014-06-16 22:59:23 +00:00
|
|
|
|
|
|
|
{- Makes a new git repository. Or, if a git repository already
|
|
|
|
- exists, returns False. -}
|
|
|
|
makeRepo :: FilePath -> Bool -> IO Bool
|
|
|
|
makeRepo path bare = ifM (probeRepoExists path)
|
|
|
|
( return False
|
|
|
|
, do
|
|
|
|
(transcript, ok) <-
|
|
|
|
processTranscript "git" (toCommand params) Nothing
|
|
|
|
unless ok $
|
|
|
|
error $ "git init failed!\nOutput:\n" ++ transcript
|
|
|
|
return True
|
|
|
|
)
|
|
|
|
where
|
|
|
|
baseparams = [Param "init", Param "--quiet"]
|
|
|
|
params
|
|
|
|
| bare = baseparams ++ [Param "--bare", File path]
|
|
|
|
| otherwise = baseparams ++ [File path]
|
|
|
|
|
|
|
|
{- Runs an action in the git repository in the specified directory. -}
|
|
|
|
inDir :: FilePath -> Annex a -> IO a
|
|
|
|
inDir dir a = do
|
|
|
|
state <- Annex.new =<< Git.Config.read =<< Git.Construct.fromPath dir
|
2017-09-30 02:36:08 +00:00
|
|
|
Annex.eval state $ a `finally` stopCoProcesses
|
2014-06-16 22:59:23 +00:00
|
|
|
|
|
|
|
{- Creates a new repository, and returns its UUID. -}
|
|
|
|
initRepo :: Bool -> Bool -> FilePath -> Maybe String -> Maybe StandardGroup -> IO UUID
|
|
|
|
initRepo True primary_assistant_repo dir desc mgroup = inDir dir $ do
|
|
|
|
initRepo' desc mgroup
|
|
|
|
{- Initialize the master branch, so things that expect
|
|
|
|
- to have it will work, before any files are added. -}
|
|
|
|
unlessM (Git.Config.isBare <$> gitRepo) $
|
2014-07-04 15:36:59 +00:00
|
|
|
void $ inRepo $ Git.Branch.commitCommand Git.Branch.AutomaticCommit
|
|
|
|
[ Param "--quiet"
|
2014-06-16 22:59:23 +00:00
|
|
|
, Param "--allow-empty"
|
|
|
|
, Param "-m"
|
|
|
|
, Param "created repository"
|
|
|
|
]
|
2019-08-30 17:54:57 +00:00
|
|
|
{- Repositories directly managed by the assistant use
|
|
|
|
- an adjusted unlocked branch with annex.thin set.
|
2014-06-16 22:59:23 +00:00
|
|
|
-
|
|
|
|
- Automatic gc is disabled, as it can be slow. Insted, gc is done
|
|
|
|
- once a day.
|
|
|
|
-}
|
|
|
|
when primary_assistant_repo $ do
|
2019-08-26 16:53:56 +00:00
|
|
|
void $ enterAdjustedBranch (LinkAdjustment UnlockAdjustment)
|
|
|
|
setConfig (annexConfig "thin") (Git.Config.boolConfig True)
|
2014-06-16 22:59:23 +00:00
|
|
|
inRepo $ Git.Command.run
|
|
|
|
[Param "config", Param "gc.auto", Param "0"]
|
|
|
|
getUUID
|
|
|
|
{- Repo already exists, could be a non-git-annex repo though so
|
|
|
|
- still initialize it. -}
|
|
|
|
initRepo False _ dir desc mgroup = inDir dir $ do
|
|
|
|
initRepo' desc mgroup
|
|
|
|
getUUID
|
|
|
|
|
|
|
|
initRepo' :: Maybe String -> Maybe StandardGroup -> Annex ()
|
|
|
|
initRepo' desc mgroup = unlessM isInitialized $ do
|
2019-02-05 18:43:23 +00:00
|
|
|
initialize desc Nothing
|
2014-06-16 22:59:23 +00:00
|
|
|
u <- getUUID
|
|
|
|
maybe noop (defaultStandardGroup u) mgroup
|
|
|
|
{- Ensure branch gets committed right away so it is
|
|
|
|
- available for merging immediately. -}
|
2018-08-02 18:06:06 +00:00
|
|
|
Annex.Branch.commit =<< Annex.Branch.commitMessage
|
2014-06-16 22:59:23 +00:00
|
|
|
|
|
|
|
{- Checks if a git repo exists at a location. -}
|
|
|
|
probeRepoExists :: FilePath -> IO Bool
|
|
|
|
probeRepoExists dir = isJust <$>
|
|
|
|
catchDefaultIO Nothing (Git.Construct.checkForRepo dir)
|