diff options
author | Joey Hess <joey@kitenet.net> | 2011-05-22 14:12:16 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-05-22 14:12:16 -0400 |
commit | 5b941980aa47ced29f702e2cc84346d517b78391 (patch) | |
tree | d5131bd216b24d15a3e0ad865d558baed8aa515d /GitRepo.hs | |
parent | f81c1f10e6ce452636eb06209c3702d2da05c49f (diff) |
Closer emulation of git's behavior when told to use "foo/.git" as a git repository instead of just "foo". Closes: #627563
Diffstat (limited to 'GitRepo.hs')
-rw-r--r-- | GitRepo.hs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/GitRepo.hs b/GitRepo.hs index f489dfe35..24bc9b5c2 100644 --- a/GitRepo.hs +++ b/GitRepo.hs @@ -77,7 +77,7 @@ import Data.Char import Data.Word (Word8) import Codec.Binary.UTF8.String (encode) import Text.Printf -import Data.List (isInfixOf, isPrefixOf) +import Data.List (isInfixOf, isPrefixOf, isSuffixOf) import System.Exit import Utility @@ -111,10 +111,24 @@ repoFromAbsPath dir | "/" `isPrefixOf` dir = do -- Git always looks for "dir.git" in preference to -- to "dir", even if dir ends in a "/". - let dir' = (dropTrailingPathSeparator dir) ++ ".git" + let canondir = dropTrailingPathSeparator dir + let dir' = canondir ++ ".git" e <- doesDirectoryExist dir' - return $ newFrom $ Dir $ if e then dir' else dir + if e + then ret dir' + else if "/.git" `isSuffixOf` canondir + then do + -- When dir == "foo/.git", git looks + -- for "foo/.git/.git", and failing + -- that, uses "foo" as the repository. + e' <- doesDirectoryExist $ dir </> ".git" + if e' + then ret dir + else ret $ takeDirectory canondir + else ret dir | otherwise = error $ "internal error, " ++ dir ++ " is not absolute" + where + ret = return . newFrom . Dir {- Remote Repo constructor. Throws exception on invalid url. -} repoFromUrl :: String -> IO Repo |