summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-04-25 13:02:54 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-04-25 13:02:54 -0400
commitb0b413c69f76bcfa46d01ff1623027707483c63c (patch)
treec554dd140a7e088fdf4aa71bb2f2418fc779faa1
parent8512a4a1a1f5367249cdb12aab75ed5d1bb42c8a (diff)
fix relative
Not currently used, but was buggy.
-rw-r--r--GitRepo.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/GitRepo.hs b/GitRepo.hs
index 543ad801a..3e177cf1b 100644
--- a/GitRepo.hs
+++ b/GitRepo.hs
@@ -59,7 +59,7 @@ module GitRepo (
prop_idempotent_deencode
) where
-import Control.Monad (unless)
+import Control.Monad (unless, when)
import System.Directory
import System.FilePath
import System.Posix.Directory
@@ -242,7 +242,11 @@ workTree Repo { location = Unknown } = undefined
relative :: Repo -> FilePath -> IO FilePath
relative repo@(Repo { location = Dir d }) file = do
cwd <- getCurrentDirectory
- return $ drop (length absrepo) (absfile cwd)
+ let file' = absfile cwd
+ let len = length absrepo
+ when (take len file' /= absrepo) $
+ error $ file ++ " is not located inside git repository " ++ absrepo
+ return $ drop (length absrepo) file'
where
-- normalize both repo and file, so that repo
-- will be substring of file
@@ -251,7 +255,7 @@ relative repo@(Repo { location = Dir d }) file = do
Nothing -> error $ "bad repo" ++ repoDescribe repo
absfile c = case (secureAbsNormPath c file) of
Just f -> f
- Nothing -> error $ file ++ " is not located inside git repository " ++ absrepo
+ Nothing -> file
relative repo _ = assertLocal repo $ error "internal"
{- Path of an URL repo. -}