fix reversions due to undocumented and buggy git behavior

* Don't use GIT_PREFIX when GIT_WORK_TREE=. because it seems git
  does not intend GIT_WORK_TREE to be relative to GIT_PREFIX in that
  case, despite GIT_WORK_TREE=.. being relative to GIT_PREFIX.
* Don't use GIT_PREFIX to fix up a relative GIT_DIR, because
  git 2.11 sets GIT_PREFIX set to a path it's not relative to.
  and apparently GIT_DIR is never relative to GIT_PREFIX.

Commit e50ed4ba48 led us down this path
by working around a git bug by relying on the barely documented GIT_PREFIX.

This commit was sponsored by Trenton Cronholm on Patreon.
This commit is contained in:
Joey Hess 2018-09-11 15:53:48 -04:00
parent 30b1e7cb34
commit fdbdf64d87
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 78 additions and 10 deletions

View file

@ -28,17 +28,17 @@ import Utility.Env.Set
-
- Also works around a git bug when running some hooks. It
- runs the hooks in the top of the repository, but if GIT_WORK_TREE
- was relative, it then points to the wrong directory. In this situation
- GIT_PREFIX contains the directory that GIT_WORK_TREE (and GIT_DIR)
- are relative to.
- was relative (but not "."), it then points to the wrong directory.
- In this situation GIT_PREFIX contains the directory that
- GIT_WORK_TREE is relative to.
-}
get :: IO Repo
get = do
prefix <- getpathenv "GIT_PREFIX"
gd <- pathenv "GIT_DIR" prefix
gd <- getpathenv "GIT_DIR"
r <- configure gd =<< fromCwd
prefix <- getpathenv "GIT_PREFIX"
wt <- maybe (worktree $ location r) Just
<$> pathenv "GIT_WORK_TREE" prefix
<$> getpathenvprefix "GIT_WORK_TREE" prefix
case wt of
Nothing -> return r
Just d -> do
@ -55,10 +55,13 @@ get = do
return (Just d)
Nothing -> return Nothing
pathenv s Nothing = getpathenv s
pathenv s (Just prefix) = getpathenv s >>= \case
Nothing -> return Nothing
Just d -> Just <$> absPath (prefix </> d)
getpathenvprefix s (Just prefix) | not (null prefix) =
getpathenv s >>= \case
Nothing -> return Nothing
Just d
| d == "." -> return (Just d)
| otherwise -> Just <$> absPath (prefix </> d)
getpathenvprefix s _ = getpathenv s
configure Nothing (Just r) = Git.Config.read r
configure (Just d) _ = do