summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--Annex.hs15
-rw-r--r--GitRepo.hs9
3 files changed, 21 insertions, 4 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..b98b07d7d
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+.git-annex/*.log merge=union
diff --git a/Annex.hs b/Annex.hs
index 3461a92cd..5adc73996 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -10,6 +10,8 @@ module Annex (
import System.Posix.Files
import System.Directory
+import System.Cmd.Utils
+import System.IO
import GitRepo
import Utility
import Locations
@@ -84,6 +86,13 @@ unannexFile state file = do
{- Sets up a git repo for git-annex. May be called repeatedly. -}
gitPrep :: GitRepo -> IO ()
gitPrep repo = do
+ -- Make sure that the repo has an annex.uuid setting.
+ if ("" == gitConfig repo "annex.uuid" "")
+ then do
+ uuid <- genUUID
+ gitRun repo ["config", "annex.uuid", uuid]
+ else return ()
+
-- configure git to use union merge driver on state files
let attrLine = stateLoc ++ "/*.log merge=union"
let attributes = gitAttributes repo
@@ -99,3 +108,9 @@ gitPrep repo = do
appendFile attributes $ attrLine ++ "\n"
gitAdd repo attributes
else return ()
+
+{- Generates a UUID. There is a library for this, but it's not packaged,
+ - so use the command line tool. -}
+genUUID :: IO String
+genUUID = do
+ pOpen ReadFromPipe "uuid" ["-m"] $ \h -> hGetLine h
diff --git a/GitRepo.hs b/GitRepo.hs
index c87bd355e..b166e3281 100644
--- a/GitRepo.hs
+++ b/GitRepo.hs
@@ -16,6 +16,7 @@ module GitRepo (
gitConfig,
gitAdd,
gitRm,
+ gitRun,
gitAttributes
) where
@@ -128,11 +129,11 @@ gitRelative repo file = drop (length absrepo) absfile
{- Stages a changed/new file in git's index. -}
gitAdd :: GitRepo -> FilePath -> IO ()
-gitAdd repo file = runGit repo ["add", file]
+gitAdd repo file = gitRun repo ["add", file]
{- Removes a file. -}
gitRm :: GitRepo -> FilePath -> IO ()
-gitRm repo file = runGit repo ["rm", file]
+gitRm repo file = gitRun repo ["rm", file]
{- Constructs a git command line operating on the specified repo. -}
gitCommandLine :: GitRepo -> [String] -> [String]
@@ -141,8 +142,8 @@ gitCommandLine repo params = assertlocal repo $
["--git-dir="++(gitDir repo), "--work-tree="++(top repo)] ++ params
{- Runs git in the specified repo. -}
-runGit :: GitRepo -> [String] -> IO ()
-runGit repo params = assertlocal repo $ do
+gitRun :: GitRepo -> [String] -> IO ()
+gitRun repo params = assertlocal repo $ do
r <- executeFile "git" True (gitCommandLine repo params) Nothing
return ()