diff options
author | Joey Hess <joey@kitenet.net> | 2014-02-24 19:40:14 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-02-24 19:40:14 -0400 |
commit | 878e7471fa09dcc36b478e1ac1fd305d5a90b7bf (patch) | |
tree | d552b8faa43078e3dfe1f8b10063ec566eced4e2 /Git/FilePath.hs | |
parent | d80c547a7d1261f158148ca85e627cc2ecb005f2 (diff) | |
download | git-repair-878e7471fa09dcc36b478e1ac1fd305d5a90b7bf.tar.gz |
merge from git-annex
Diffstat (limited to 'Git/FilePath.hs')
-rw-r--r-- | Git/FilePath.hs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Git/FilePath.hs b/Git/FilePath.hs index 4189244..42eb081 100644 --- a/Git/FilePath.hs +++ b/Git/FilePath.hs @@ -20,12 +20,15 @@ module Git.FilePath ( asTopFilePath, InternalGitPath, toInternalGitPath, - fromInternalGitPath + fromInternalGitPath, + absoluteGitPath ) where import Common import Git +import qualified System.FilePath.Posix + {- A FilePath, relative to the top of the git repository. -} newtype TopFilePath = TopFilePath { getTopFilePath :: FilePath } deriving (Show) @@ -48,8 +51,7 @@ asTopFilePath file = TopFilePath file - it internally. - - On Windows, git uses '/' to separate paths stored in the repository, - - despite Windows using '\'. Also, git on windows dislikes paths starting - - with "./" or ".\". + - despite Windows using '\'. - -} type InternalGitPath = String @@ -58,11 +60,7 @@ toInternalGitPath :: FilePath -> InternalGitPath #ifndef mingw32_HOST_OS toInternalGitPath = id #else -toInternalGitPath p = - let p' = replace "\\" "/" p - in if "./" `isPrefixOf` p' - then dropWhile (== '/') (drop 1 p') - else p' +toInternalGitPath = replace "\\" "/" #endif fromInternalGitPath :: InternalGitPath -> FilePath @@ -71,3 +69,10 @@ fromInternalGitPath = id #else fromInternalGitPath = replace "/" "\\" #endif + +{- isAbsolute on Windows does not think "/foo" or "\foo" is absolute, + - so try posix paths. + -} +absoluteGitPath :: FilePath -> Bool +absoluteGitPath p = isAbsolute p || + System.FilePath.Posix.isAbsolute (toInternalGitPath p) |