summaryrefslogtreecommitdiff
path: root/git-union-merge.hs
blob: 18c88b1a9e6b263cb6fa1ccd1cf73f32e183db71 (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
50
{- git-union-merge program
 -
 - Copyright 2011 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

import System.Environment

import Common
import qualified Git.UnionMerge
import qualified Git.Config
import qualified Git.CurrentRepo
import qualified Git.Branch
import qualified Git.Index
import qualified Git
import Utility.FileSystemEncoding

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.localGitDir g </> "index.git-union-merge"

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

cleanup :: Git.Repo -> IO ()
cleanup g = nukeFile $ tmpIndex g

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

main :: IO ()
main = do
	useFileSystemEncoding
	[aref, bref, newref] <- map Git.Ref <$> parseArgs
	g <- Git.Config.read =<< Git.CurrentRepo.get
	_ <- Git.Index.override (tmpIndex g) g
	setup g
	Git.UnionMerge.merge aref bref g
	_ <- Git.Branch.commit Git.Branch.ManualCommit False "union merge" newref [aref, bref] g
	cleanup g