summaryrefslogtreecommitdiff
path: root/Remote/Git.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-05-22 13:42:17 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-05-22 13:42:17 -0400
commit8f009cb87ecc0df3ada184db88f05dbd57067109 (patch)
tree18bf136f6ea5a2850da27eb8cd2afad992fa54bf /Remote/Git.hs
parent211e55ec8e105607b7b0a9b94bd7c3c2767454ce (diff)
initremote/enableremote: Basic support for using with regular git remotes
initremote stores the location of an already existing git remote, and enableremote setups up a remote using its stored location.
Diffstat (limited to 'Remote/Git.hs')
-rw-r--r--Remote/Git.hs33
1 files changed, 32 insertions, 1 deletions
diff --git a/Remote/Git.hs b/Remote/Git.hs
index 5b9a72a01..da702730a 100644
--- a/Remote/Git.hs
+++ b/Remote/Git.hs
@@ -22,6 +22,7 @@ import qualified Git.Config
import qualified Git.Construct
import qualified Git.Command
import qualified Git.GCrypt
+import qualified Git.Types as Git
import qualified Annex
import Logs.Presence
import Annex.Transfer
@@ -50,6 +51,7 @@ import Remote.Helper.Messages
import qualified Remote.Helper.Ssh as Ssh
import qualified Remote.GCrypt
import Config.Files
+import Creds
import Control.Concurrent
import Control.Concurrent.MSampleVar
@@ -62,7 +64,7 @@ remote = RemoteType {
typename = "git",
enumerate = list,
generate = gen,
- setup = error "not supported"
+ setup = gitSetup
}
list :: Annex [Git.Repo]
@@ -80,6 +82,35 @@ list = do
Git.Construct.remoteNamed n $
Git.Construct.fromRemoteLocation url g
+{- Git remotes are normally set up using standard git command, not
+ - git-annex initremote and enableremote.
+ -
+ - For initremote, the git remote must already be set up, and have a uuid.
+ - Initremote simply remembers its location.
+ -
+ - enableremote simply sets up a git remote using the stored location.
+ - No attempt is made to make the remote be accessible via ssh key setup,
+ - etc.
+ -}
+gitSetup :: Maybe UUID -> Maybe CredPair -> RemoteConfig -> Annex (RemoteConfig, UUID)
+gitSetup Nothing _ c = do
+ let location = fromMaybe (error "Specify location=url") $
+ Url.parseURIRelaxed =<< M.lookup "location" c
+ g <- Annex.gitRepo
+ u <- case filter (\r -> Git.location r == Git.Url location) (Git.remotes g) of
+ [r] -> getRepoUUID r
+ [] -> error "could not find existing git remote with specified location"
+ _ -> error "found multiple git remotes with specified location"
+ return (c, u)
+gitSetup (Just u) _ c = do
+ inRepo $ Git.Command.run
+ [ Param "remote"
+ , Param "add"
+ , Param $ fromMaybe (error "no name") (M.lookup "name" c)
+ , Param $ fromMaybe (error "no location") (M.lookup "location" c)
+ ]
+ return (c, u)
+
{- It's assumed to be cheap to read the config of non-URL remotes, so this is
- done each time git-annex is run in a way that uses remotes.
-