summaryrefslogtreecommitdiff
path: root/GitRepo.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-22 22:56:27 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-22 22:56:27 -0400
commita4ef0e4da4431755c98fa104204af5254727e7a6 (patch)
tree1b151d2c83ce5e7eaa815367c13e814a2d560044 /GitRepo.hs
parentc4e6730042e64e3b2f92626aee4a6b38a8f9c70c (diff)
bugfix: restore index file env var
This fixes precommit, since in that hook, git sets the env var to write to the lock file, which avoids git add failing due to the presence of the lock file. (Took me a good hour and a half of confusion to figure this out.) Test suite now passes 100%! Only the upgrade code still remains to be written.
Diffstat (limited to 'GitRepo.hs')
-rw-r--r--GitRepo.hs23
1 files changed, 14 insertions, 9 deletions
diff --git a/GitRepo.hs b/GitRepo.hs
index d1f122fba..4a6c4d763 100644
--- a/GitRepo.hs
+++ b/GitRepo.hs
@@ -60,7 +60,6 @@ module GitRepo (
repoAbsPath,
reap,
useIndex,
- useDefaultIndex,
hashObject,
getSha,
shaSize,
@@ -79,6 +78,7 @@ import System.Cmd.Utils
import IO (bracket_)
import Data.String.Utils
import System.IO
+import IO (try)
import qualified Data.Map as Map hiding (map, split)
import Network.URI
import Data.Maybe
@@ -88,7 +88,7 @@ import Codec.Binary.UTF8.String (encode)
import Text.Printf
import Data.List (isInfixOf, isPrefixOf, isSuffixOf)
import System.Exit
-import System.Posix.Env (setEnv, unsetEnv)
+import System.Posix.Env (setEnv, unsetEnv, getEnv)
import Utility
@@ -391,13 +391,18 @@ reap = do
r <- catch (getAnyProcessStatus False True) (\_ -> return Nothing)
maybe (return ()) (const reap) r
-{- Forces git to use the specified index file. -}
-useIndex :: FilePath -> IO ()
-useIndex index = setEnv "GIT_INDEX_FILE" index True
-
-{- Undoes useIndex -}
-useDefaultIndex :: IO ()
-useDefaultIndex = unsetEnv "GIT_INDEX_FILE"
+{- Forces git to use the specified index file.
+ - Returns an action that will reset back to the default
+ - index file. -}
+useIndex :: FilePath -> IO (IO ())
+useIndex index = do
+ res <- try $ getEnv var
+ setEnv var index True
+ return $ reset res
+ where
+ var = "GIT_INDEX_FILE"
+ reset (Right (Just v)) = setEnv var v True
+ reset _ = unsetEnv var
{- Injects some content into git, returning its hash. -}
hashObject :: Repo -> String -> IO String