git-annex/git-union-merge.hs

51 lines
1.1 KiB
Haskell
Raw Normal View History

{- git-union-merge program
-
- Copyright 2011 Joey Hess <joey@kitenet.net>
-
- 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.Construct
2011-12-13 19:22:43 +00:00
import qualified Git.Branch
2011-12-14 19:30:14 +00:00
import qualified Git.Index
import qualified Git
header :: String
2011-06-21 02:21:02 +00:00
header = "Usage: git-union-merge ref ref newref"
usage :: IO a
usage = error $ "bad parameters\n\n" ++ header
2011-06-21 20:08:09 +00:00
tmpIndex :: Git.Repo -> FilePath
2011-08-19 16:59:07 +00:00
tmpIndex g = Git.gitDir g </> "index.git-union-merge"
2011-06-21 20:08:09 +00:00
setup :: Git.Repo -> IO ()
2011-09-21 03:24:48 +00:00
setup = cleanup -- idempotency
2011-06-21 20:08:09 +00:00
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
2011-06-21 18:09:06 +00:00
main :: IO ()
main = do
[aref, bref, newref] <- map Git.Ref <$> parseArgs
g <- Git.Config.read =<< Git.Construct.fromCwd
2011-12-14 19:30:14 +00:00
_ <- Git.Index.override (tmpIndex g)
setup g
Git.UnionMerge.merge aref bref g
2011-12-13 19:22:43 +00:00
_ <- Git.Branch.commit "union merge" newref [aref, bref] g
cleanup g