From 3c7357ee388795149e922d344bdbf32e1d1d5810 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 30 Nov 2013 14:30:56 -0400 Subject: merge from git-annex --- Git/Config.hs | 9 +++++++-- Git/Index.hs | 32 ++++++++++++++++++++++++++++++++ Git/Repair.hs | 4 +--- 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 Git/Index.hs (limited to 'Git') diff --git a/Git/Config.hs b/Git/Config.hs index 1919ece..b5c1be0 100644 --- a/Git/Config.hs +++ b/Git/Config.hs @@ -110,8 +110,13 @@ store s repo = do -} updateLocation :: Repo -> IO Repo updateLocation r@(Repo { location = LocalUnknown d }) - | isBare r = updateLocation' r $ Local d Nothing - | otherwise = updateLocation' r $ Local (d ".git") (Just d) + | isBare r = ifM (doesDirectoryExist dotgit) + ( updateLocation' r $ Local dotgit Nothing + , updateLocation' r $ Local d Nothing + ) + | otherwise = updateLocation' r $ Local dotgit (Just d) + where + dotgit = (d ".git") updateLocation r@(Repo { location = l@(Local {}) }) = updateLocation' r l updateLocation r = return r diff --git a/Git/Index.hs b/Git/Index.hs new file mode 100644 index 0000000..d9d5b03 --- /dev/null +++ b/Git/Index.hs @@ -0,0 +1,32 @@ +{- git index file stuff + - + - Copyright 2011 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Git.Index where + +import Common +import Git +import Utility.Env + +{- Forces git to use the specified index file. + - + - Returns an action that will reset back to the default + - index file. + - + - Warning: Not thread safe. + -} +override :: FilePath -> IO (IO ()) +override index = do + res <- getEnv var + void $ setEnv var index True + return $ void $ reset res + where + var = "GIT_INDEX_FILE" + reset (Just v) = setEnv var v True + reset _ = unsetEnv var + +indexFile :: Repo -> FilePath +indexFile r = localGitDir r "index" diff --git a/Git/Repair.hs b/Git/Repair.hs index 1495d23..5afa5f9 100644 --- a/Git/Repair.hs +++ b/Git/Repair.hs @@ -25,6 +25,7 @@ import Git.Objects import Git.Sha import Git.Types import Git.Fsck +import Git.Index import qualified Git.Config as Config import qualified Git.Construct as Construct import qualified Git.LsTree as LsTree @@ -376,9 +377,6 @@ rewriteIndex missing r UpdateIndex.stageFile sha blobtype file r reinject _ = return Nothing -indexFile :: Repo -> FilePath -indexFile r = localGitDir r "index" - newtype GoodCommits = GoodCommits (S.Set Sha) emptyGoodCommits :: GoodCommits -- cgit v1.2.3