diff options
author | Joey Hess <joey@kitenet.net> | 2010-10-10 02:22:47 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-10-10 02:22:47 -0400 |
commit | 852ead470756744cd6663ee2d537f3d281f1e7c8 (patch) | |
tree | e24e393f7f6174b0f2a31c795472163502d54882 | |
parent | 60c672e444decf59c20beb70b89f030ad9d62b3e (diff) |
add gitPrep to handle .gitattributes
-rw-r--r-- | GitRepo.hs | 27 | ||||
-rw-r--r-- | git-annex.hs | 4 |
2 files changed, 28 insertions, 3 deletions
diff --git a/GitRepo.hs b/GitRepo.hs index 2e7fff22e..21c683bd2 100644 --- a/GitRepo.hs +++ b/GitRepo.hs @@ -8,6 +8,12 @@ import System.Path import Data.String.Utils import Utility +{- Long-term state is stored in files inside the .git-annex directory + - in the git repository. -} +stateLoc = ".git-annex" +gitStateDir :: String -> String +gitStateDir repo = repo ++ "/" ++ stateLoc ++ "/" + {- Given a relative or absolute filename, calculates the name to use - relative to a git repository directory (which must be absolute). - This is the same form displayed and used by git. -} @@ -23,9 +29,28 @@ gitRelative repo file = drop (length absrepo) absfile Just f -> f Nothing -> error $ file ++ " is not located inside git repository " ++ absrepo +{- Sets up the current git repo for git-annex. May be called repeatedly. -} +gitPrep :: IO () +gitPrep = do + repo <- repoTop + bare <- isBareRepo repo + -- configure git to use union merge driver on state files + let attributes = repo ++ "/.gitattributes" + let attrLine = stateLoc ++ "/* merge=union" + exists <- doesFileExist attributes + if (not bare) + then if (not exists) + then writeFile attributes $ attrLine ++ "\n" + else do + content <- readFile attributes + if (all (/= attrLine) (lines content)) + then appendFile attributes $ attrLine ++ "\n" + else return () + else return () {- Returns the path to the current repository's .git directory. - - (For a bare repository, that is the root of the repository.) -} + - (For a bare repository, that is the root of the repository.) + - TODO: support GIT_DIR -} gitDir :: IO String gitDir = do repo <- repoTop diff --git a/git-annex.hs b/git-annex.hs index a57e9e2db..e8032a132 100644 --- a/git-annex.hs +++ b/git-annex.hs @@ -2,7 +2,7 @@ - -} import LocationLog +import GitRepo main = do - l <- readLog "demo.log" - putStrLn "hi" + gitPrep |