summaryrefslogtreecommitdiff
path: root/Utility.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-28 17:17:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-28 17:17:18 -0400
commitabf084f628a8c5f5a3685dbb2826739e3e38541e (patch)
tree1b24036e91aef3a2c046af809f49250bd060f939 /Utility.hs
parent52ec6e748d5ef8350e9788d0f19dc5c3d609ab86 (diff)
Bugfix: Always correctly handle gitattributes when in a subdirectory of the repository.
Diffstat (limited to 'Utility.hs')
-rw-r--r--Utility.hs20
1 files changed, 11 insertions, 9 deletions
diff --git a/Utility.hs b/Utility.hs
index 882492a2d..0f7ce42aa 100644
--- a/Utility.hs
+++ b/Utility.hs
@@ -8,6 +8,7 @@
module Utility (
hGetContentsStrict,
parentDir,
+ absPath,
relPathCwdToDir,
relPathDirToDir,
boolSystem,
@@ -44,24 +45,25 @@ parentDir dir =
slash = if isAbsolute dir then s else ""
s = [pathSeparator]
+{- Converts a filename into a normalized, absolute path. -}
+absPath :: FilePath -> IO FilePath
+absPath file = do
+ cwd <- getCurrentDirectory
+ case absNormPath cwd file of
+ Just f -> return f
+ Nothing -> error $ "unable to normalize " ++ file
+
{- Constructs a relative path from the CWD to a directory.
-
- For example, assuming CWD is /tmp/foo/bar:
- relPathCwdToDir "/tmp/foo" == "../"
- relPathCwdToDir "/tmp/foo/bar" == ""
- - relPathCwdToDir "/tmp/foo/bar" == ""
-}
relPathCwdToDir :: FilePath -> IO FilePath
relPathCwdToDir dir = do
cwd <- getCurrentDirectory
- let absdir = absnorm cwd
- return $ relPathDirToDir cwd absdir
- where
- -- absolute, normalized form of the directory
- absnorm cwd =
- case absNormPath cwd dir of
- Just d -> d
- Nothing -> error $ "unable to normalize " ++ dir
+ a <- absPath dir
+ return $ relPathDirToDir cwd a
{- Constructs a relative path from one directory to another.
-