summaryrefslogtreecommitdiff
path: root/git-union-merge.hs
blob: e8ac0a0c54f490b273e31fb031ba8fa318402568 (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
{- git-union-merge program
 -
 - Copyright 2011 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

import System.Environment
import System.FilePath
import System.Directory
import Control.Monad (when)

import GitUnionMerge
import qualified GitRepo as Git

header :: String
header = "Usage: git-union-merge ref ref newref"

usage :: IO a
usage = error $ "bad parameters\n\n" ++ header

tmpIndex :: Git.Repo -> FilePath
tmpIndex g = Git.workTree g </> Git.gitDir g </> "index.git-union-merge"

setup :: Git.Repo -> IO ()
setup g = do
	cleanup g -- idempotency

cleanup :: Git.Repo -> IO ()
cleanup g = do
	e' <- doesFileExist (tmpIndex g)
	when e' $ removeFile (tmpIndex g)

parseArgs :: IO [String]
parseArgs = do
	args <- getArgs
	if (length args /= 3)
		then usage
		else return args

main :: IO ()
main = do
	[aref, bref, newref] <- parseArgs
	g <- Git.configRead =<< Git.repoFromCwd
	Git.useIndex (tmpIndex g)
	setup g
	unionMerge g aref bref newref False
	cleanup g