summaryrefslogtreecommitdiff
path: root/git-union-merge.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-21 16:08:09 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-21 16:08:09 -0400
commit7e7428f173ba1b72b4de69fd482f44161ee84420 (patch)
tree7db187ad39b67905fb0de179c74fcd48ff603663 /git-union-merge.hs
parenta5e6802b5b6f9354e065936998d9882e8ceecb5b (diff)
refactor
Diffstat (limited to 'git-union-merge.hs')
-rw-r--r--git-union-merge.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/git-union-merge.hs b/git-union-merge.hs
index 62a79a4c2..12f49adc6 100644
--- a/git-union-merge.hs
+++ b/git-union-merge.hs
@@ -6,6 +6,9 @@
-}
import System.Environment
+import System.FilePath
+import System.Directory
+import Control.Monad (when)
import GitUnionMerge
import qualified GitRepo as Git
@@ -16,6 +19,18 @@ 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
@@ -27,4 +42,7 @@ main :: IO ()
main = do
[aref, bref, newref] <- parseArgs
g <- Git.configRead =<< Git.repoFromCwd
- unionMerge g aref bref newref
+ Git.withIndex (tmpIndex g) $ do
+ setup g
+ unionMerge g aref bref newref
+ cleanup g