2011-03-30 18:00:54 +00:00
|
|
|
{- common functions for special remotes
|
|
|
|
-
|
|
|
|
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2011-08-17 00:49:54 +00:00
|
|
|
module Remote.Helper.Special where
|
2011-03-30 18:00:54 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2011-06-02 01:56:04 +00:00
|
|
|
import Types.Remote
|
2011-06-30 17:16:57 +00:00
|
|
|
import qualified Git
|
2011-12-14 19:56:11 +00:00
|
|
|
import qualified Git.Command
|
2011-12-13 19:05:07 +00:00
|
|
|
import qualified Git.Construct
|
2011-03-30 18:00:54 +00:00
|
|
|
|
|
|
|
{- Special remotes don't have a configured url, so Git.Repo does not
|
|
|
|
- automatically generate remotes for them. This looks for a different
|
|
|
|
- configuration key instead.
|
|
|
|
-}
|
|
|
|
findSpecialRemotes :: String -> Annex [Git.Repo]
|
|
|
|
findSpecialRemotes s = do
|
2011-12-14 19:30:14 +00:00
|
|
|
m <- fromRepo Git.config
|
|
|
|
liftIO $ mapM construct $ remotepairs m
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
remotepairs = M.toList . M.filterWithKey match
|
|
|
|
construct (k,_) = Git.Construct.remoteNamedFromKey k Git.Construct.fromUnknown
|
|
|
|
match k _ = startswith "remote." k && endswith (".annex-"++s) k
|
2011-03-30 18:00:54 +00:00
|
|
|
|
|
|
|
{- Sets up configuration for a special remote in .git/config. -}
|
2011-04-15 19:09:36 +00:00
|
|
|
gitConfigSpecialRemote :: UUID -> RemoteConfig -> String -> String -> Annex ()
|
2011-03-30 18:32:08 +00:00
|
|
|
gitConfigSpecialRemote u c k v = do
|
2011-11-08 19:34:10 +00:00
|
|
|
set ("annex-"++k) v
|
|
|
|
set ("annex-uuid") (fromUUID u)
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2013-03-03 17:39:07 +00:00
|
|
|
set a b = inRepo $ Git.Command.run
|
|
|
|
[Param "config", Param (configsetting a), Param b]
|
2012-11-11 04:51:07 +00:00
|
|
|
remotename = fromJust (M.lookup "name" c)
|
|
|
|
configsetting s = "remote." ++ remotename ++ "." ++ s
|