unify handling of unusual GIT_INDEX_FILE relative path

This is probably a git bug that stuck in its interface.
This commit is contained in:
Joey Hess 2016-05-17 14:40:53 -04:00
parent e81b1bc9e7
commit 766728c8cf
Failed to extract signature
4 changed files with 17 additions and 10 deletions

View file

@ -19,10 +19,9 @@ import qualified Annex
{- Runs an action using a different git index file. -} {- Runs an action using a different git index file. -}
withIndexFile :: FilePath -> Annex a -> Annex a withIndexFile :: FilePath -> Annex a -> Annex a
withIndexFile f a = do withIndexFile f a = do
-- Workaround http://thread.gmane.org/gmane.comp.version-control.git/294880 f' <- inRepo $ indexEnvVal f
absf <- liftIO $ absPath f
withAltRepo withAltRepo
(\g -> addGitEnv g indexEnv absf) (\g -> addGitEnv g indexEnv f')
(\g g' -> g' { gitEnv = gitEnv g }) (\g g' -> g' { gitEnv = gitEnv g })
a a

View file

@ -9,11 +9,20 @@ module Git.Index where
import Common import Common
import Git import Git
import Git.FilePath
import Utility.Env import Utility.Env
indexEnv :: String indexEnv :: String
indexEnv = "GIT_INDEX_FILE" indexEnv = "GIT_INDEX_FILE"
{- When relative, GIT_INDEX_FILE is interpreted by git as being
- relative to the top of the work tree of the git repository,
- not to the CWD. -}
indexEnvVal :: FilePath -> Repo -> IO String
indexEnvVal index r
| isAbsolute index = return index
| otherwise = getTopFilePath <$> toTopFilePath index r
{- Forces git to use the specified index file. {- Forces git to use the specified index file.
- -
- Returns an action that will reset back to the default - Returns an action that will reset back to the default
@ -21,12 +30,11 @@ indexEnv = "GIT_INDEX_FILE"
- -
- Warning: Not thread safe. - Warning: Not thread safe.
-} -}
override :: FilePath -> IO (IO ()) override :: FilePath -> Repo -> IO (IO ())
override index = do override index r = do
res <- getEnv var res <- getEnv var
-- Workaround http://thread.gmane.org/gmane.comp.version-control.git/294880 val <- indexEnvVal index r
absindex <- absPath index setEnv var val True
setEnv var absindex True
return $ reset res return $ reset res
where where
var = "GIT_INDEX_FILE" var = "GIT_INDEX_FILE"

2
debian/changelog vendored
View file

@ -15,7 +15,7 @@ git-annex (6.20160512) UNRELEASED; urgency=medium
thing) thing)
* adjust: Add --fix adjustment, which is useful when the git directory * adjust: Add --fix adjustment, which is useful when the git directory
is in a nonstandard place. is in a nonstandard place.
* Work around git bug in handling of relative path to GIT_INDEX_FILE * Work around git weirdness in handling of relative path to GIT_INDEX_FILE
when in a subdirectory of the repository. This affected git annex view. when in a subdirectory of the repository. This affected git annex view.
* Fix crash when entering/changing view in a subdirectory of a repo that * Fix crash when entering/changing view in a subdirectory of a repo that
has a dotfile in its root. has a dotfile in its root.

View file

@ -41,7 +41,7 @@ main :: IO ()
main = do main = do
[aref, bref, newref] <- map Git.Ref <$> parseArgs [aref, bref, newref] <- map Git.Ref <$> parseArgs
g <- Git.Config.read =<< Git.CurrentRepo.get g <- Git.Config.read =<< Git.CurrentRepo.get
_ <- Git.Index.override $ tmpIndex g _ <- Git.Index.override (tmpIndex g) g
setup g setup g
Git.UnionMerge.merge aref bref g Git.UnionMerge.merge aref bref g
_ <- Git.Branch.commit Git.Branch.ManualCommit False "union merge" newref [aref, bref] g _ <- Git.Branch.commit Git.Branch.ManualCommit False "union merge" newref [aref, bref] g