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.
This commit is contained in:
parent
c4e6730042
commit
a4ef0e4da4
2 changed files with 24 additions and 19 deletions
16
Branch.hs
16
Branch.hs
|
@ -68,16 +68,19 @@ genIndex g = do
|
||||||
|
|
||||||
{- Runs an action using the branch's index file. -}
|
{- Runs an action using the branch's index file. -}
|
||||||
withIndex :: Annex a -> Annex a
|
withIndex :: Annex a -> Annex a
|
||||||
withIndex a = do
|
withIndex = withIndex' False
|
||||||
|
withIndex' :: Bool -> Annex a -> Annex a
|
||||||
|
withIndex' bootstrapping a = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
let f = index g
|
let f = index g
|
||||||
liftIO $ Git.useIndex f
|
reset <- liftIO $ Git.useIndex f
|
||||||
|
|
||||||
|
unless bootstrapping $ do
|
||||||
e <- liftIO $ doesFileExist f
|
e <- liftIO $ doesFileExist f
|
||||||
unless e $ liftIO $ genIndex g
|
unless e $ liftIO $ genIndex g
|
||||||
|
|
||||||
r <- a
|
r <- a
|
||||||
liftIO $ Git.useDefaultIndex
|
liftIO reset
|
||||||
return r
|
return r
|
||||||
|
|
||||||
withIndexUpdate :: Annex a -> Annex a
|
withIndexUpdate :: Annex a -> Annex a
|
||||||
|
@ -121,11 +124,8 @@ create = do
|
||||||
inorigin <- refexists origin
|
inorigin <- refexists origin
|
||||||
if inorigin
|
if inorigin
|
||||||
then liftIO $ Git.run g "branch" [Param name, Param origin]
|
then liftIO $ Git.run g "branch" [Param name, Param origin]
|
||||||
else liftIO $ do
|
else withIndex' True $
|
||||||
let f = index g
|
liftIO $ GitUnionMerge.commit g "branch created" fullname []
|
||||||
liftIO $ Git.useIndex f
|
|
||||||
GitUnionMerge.commit g "branch created" fullname []
|
|
||||||
liftIO $ Git.useDefaultIndex
|
|
||||||
where
|
where
|
||||||
origin = "origin/" ++ name
|
origin = "origin/" ++ name
|
||||||
refexists ref = do
|
refexists ref = do
|
||||||
|
|
23
GitRepo.hs
23
GitRepo.hs
|
@ -60,7 +60,6 @@ module GitRepo (
|
||||||
repoAbsPath,
|
repoAbsPath,
|
||||||
reap,
|
reap,
|
||||||
useIndex,
|
useIndex,
|
||||||
useDefaultIndex,
|
|
||||||
hashObject,
|
hashObject,
|
||||||
getSha,
|
getSha,
|
||||||
shaSize,
|
shaSize,
|
||||||
|
@ -79,6 +78,7 @@ import System.Cmd.Utils
|
||||||
import IO (bracket_)
|
import IO (bracket_)
|
||||||
import Data.String.Utils
|
import Data.String.Utils
|
||||||
import System.IO
|
import System.IO
|
||||||
|
import IO (try)
|
||||||
import qualified Data.Map as Map hiding (map, split)
|
import qualified Data.Map as Map hiding (map, split)
|
||||||
import Network.URI
|
import Network.URI
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
@ -88,7 +88,7 @@ import Codec.Binary.UTF8.String (encode)
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import Data.List (isInfixOf, isPrefixOf, isSuffixOf)
|
import Data.List (isInfixOf, isPrefixOf, isSuffixOf)
|
||||||
import System.Exit
|
import System.Exit
|
||||||
import System.Posix.Env (setEnv, unsetEnv)
|
import System.Posix.Env (setEnv, unsetEnv, getEnv)
|
||||||
|
|
||||||
import Utility
|
import Utility
|
||||||
|
|
||||||
|
@ -391,13 +391,18 @@ reap = do
|
||||||
r <- catch (getAnyProcessStatus False True) (\_ -> return Nothing)
|
r <- catch (getAnyProcessStatus False True) (\_ -> return Nothing)
|
||||||
maybe (return ()) (const reap) r
|
maybe (return ()) (const reap) r
|
||||||
|
|
||||||
{- Forces git to use the specified index file. -}
|
{- Forces git to use the specified index file.
|
||||||
useIndex :: FilePath -> IO ()
|
- Returns an action that will reset back to the default
|
||||||
useIndex index = setEnv "GIT_INDEX_FILE" index True
|
- index file. -}
|
||||||
|
useIndex :: FilePath -> IO (IO ())
|
||||||
{- Undoes useIndex -}
|
useIndex index = do
|
||||||
useDefaultIndex :: IO ()
|
res <- try $ getEnv var
|
||||||
useDefaultIndex = unsetEnv "GIT_INDEX_FILE"
|
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. -}
|
{- Injects some content into git, returning its hash. -}
|
||||||
hashObject :: Repo -> String -> IO String
|
hashObject :: Repo -> String -> IO String
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue