summaryrefslogtreecommitdiff
path: root/Remote
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-08-16 20:48:11 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-08-16 20:48:11 -0400
commit07f2e7ee726f3d7f60cd478e928afc69db60c0c8 (patch)
treebb2bdef253d2e182e1ba94f3620121a5ed815da7 /Remote
parent5000aba76e6f066fd310d9635ea4369f07684b86 (diff)
support reading git config from http remotes
The config file is downloaded to a temp file, and git-config run on that to parse it.
Diffstat (limited to 'Remote')
-rw-r--r--Remote/Git.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/Remote/Git.hs b/Remote/Git.hs
index de51c891e..c8facb47a 100644
--- a/Remote/Git.hs
+++ b/Remote/Git.hs
@@ -12,6 +12,7 @@ import Control.Monad.State (liftIO)
import qualified Data.Map as M
import System.Cmd.Utils
import System.Posix.Files
+import System.IO
import Types
import Types.Remote
@@ -24,7 +25,8 @@ import qualified Content
import Messages
import Utility.CopyFile
import Utility.RsyncFile
-import Remote.Ssh
+import Remote.Helper.Ssh
+import qualified Remote.Helper.Url as Url
import Config
remote :: RemoteType Annex
@@ -75,6 +77,7 @@ tryGitConfigRead :: Git.Repo -> Annex Git.Repo
tryGitConfigRead r
| not $ M.null $ Git.configMap r = return r -- already read
| Git.repoIsSsh r = store $ onRemote r (pipedconfig, r) "configlist" []
+ | Git.repoIsHttp r = store $ safely $ geturlconfig
| Git.repoIsUrl r = return r
| otherwise = store $ safely $ Git.configRead r
where
@@ -85,9 +88,19 @@ tryGitConfigRead r
case result of
Left _ -> return r
Right r' -> return r'
+
pipedconfig cmd params = safely $
pOpen ReadFromPipe cmd (toCommand params) $
Git.hConfigRead r
+
+ geturlconfig = do
+ s <- Url.get (Git.repoLocation r ++ "/config")
+ withTempFile "git-annex.tmp" $ \tmpfile -> \h -> do
+ hPutStr h s
+ hClose h
+ pOpen ReadFromPipe "git" ["config", "--list", "--file", tmpfile] $
+ Git.hConfigRead r
+
store a = do
r' <- a
g <- Annex.gitRepo
@@ -95,6 +108,7 @@ tryGitConfigRead r
let g' = Git.remotesAdd g $ exchange l r'
Annex.changeState $ \s -> s { Annex.repo = g' }
return r'
+
exchange [] _ = []
exchange (old:ls) new =
if Git.repoRemoteName old == Git.repoRemoteName new