summaryrefslogtreecommitdiff
path: root/Command/XMPPGit.hs
blob: 20e7f07430a81be520c3048d412b4418417a5db8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{- git-annex command
 -
 - Copyright 2012 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.XMPPGit where

import Common.Annex
import Command
import Assistant.XMPP.Git

cmd :: Command
cmd = noCommit $ dontCheck repoExists $
	noRepo (parseparams startNoRepo) $ 
		command "xmppgit" SectionPlumbing "git to XMPP relay"
			paramNothing (parseparams seek)
  where
	parseparams = withParams

seek :: CmdParams -> CommandSeek
seek = withWords start

start :: CmdParams -> CommandStart
start _ = do
	liftIO gitRemoteHelper
	liftIO xmppGitRelay
	stop

startNoRepo :: CmdParams -> IO ()
startNoRepo _ = xmppGitRelay

{- A basic implementation of the git-remote-helpers protocol. -}
gitRemoteHelper :: IO ()
gitRemoteHelper = do
	expect "capabilities"
	respond ["connect"]
	expect "connect git-receive-pack"
	respond []
  where
	expect s = do
		gitcmd <- getLine
		unless (gitcmd == s) $
			error $ "git-remote-helpers protocol error: expected: " ++ s ++ ", but got: " ++ gitcmd
	respond l = do
		mapM_ putStrLn l
		putStrLn ""
		hFlush stdout