Support repositories created with --separate-git-dir. Closes: #684405
This commit is contained in:
parent
ba0334116c
commit
da63b7e96c
2 changed files with 36 additions and 18 deletions
|
@ -28,13 +28,19 @@ import Git.Types
|
||||||
import Git
|
import Git
|
||||||
import qualified Git.Url as Url
|
import qualified Git.Url as Url
|
||||||
|
|
||||||
{- Finds the git repository used for the Cwd, which may be in a parent
|
{- Finds the git repository used for the cwd, which may be in a parent
|
||||||
- directory. -}
|
- directory. -}
|
||||||
fromCwd :: IO Repo
|
fromCwd :: IO Repo
|
||||||
fromCwd = getCurrentDirectory >>= seekUp isRepoTop >>= maybe norepo makerepo
|
fromCwd = getCurrentDirectory >>= seekUp checkForRepo
|
||||||
where
|
where
|
||||||
makerepo = newFrom . LocalUnknown
|
|
||||||
norepo = error "Not in a git repository."
|
norepo = error "Not in a git repository."
|
||||||
|
seekUp check dir = do
|
||||||
|
r <- check dir
|
||||||
|
case r of
|
||||||
|
Nothing -> case parentDir dir of
|
||||||
|
"" -> norepo
|
||||||
|
d -> seekUp check d
|
||||||
|
Just loc -> newFrom loc
|
||||||
|
|
||||||
{- Local Repo constructor, accepts a relative or absolute path. -}
|
{- Local Repo constructor, accepts a relative or absolute path. -}
|
||||||
fromPath :: FilePath -> IO Repo
|
fromPath :: FilePath -> IO Repo
|
||||||
|
@ -201,22 +207,33 @@ expandTilde = expandt True
|
||||||
| c == '/' = (n, cs)
|
| c == '/' = (n, cs)
|
||||||
| otherwise = findname (n++[c]) cs
|
| otherwise = findname (n++[c]) cs
|
||||||
|
|
||||||
seekUp :: (FilePath -> IO Bool) -> FilePath -> IO (Maybe FilePath)
|
checkForRepo :: FilePath -> IO (Maybe RepoLocation)
|
||||||
seekUp want dir =
|
checkForRepo dir =
|
||||||
ifM (want dir)
|
check isRepo $
|
||||||
( return $ Just dir
|
check gitDirFile $
|
||||||
, case parentDir dir of
|
check isBareRepo $
|
||||||
"" -> return Nothing
|
return Nothing
|
||||||
d -> seekUp want d
|
|
||||||
)
|
|
||||||
|
|
||||||
isRepoTop :: FilePath -> IO Bool
|
|
||||||
isRepoTop dir = ifM isRepo ( return True , isBareRepo )
|
|
||||||
where
|
where
|
||||||
isRepo = gitSignature (".git" </> "config")
|
check test cont = maybe cont (return . Just) =<< test
|
||||||
isBareRepo = ifM (doesDirectoryExist $ dir </> "objects")
|
checkdir c = ifM c
|
||||||
( gitSignature "config" , return False )
|
( return $ Just $ LocalUnknown dir
|
||||||
gitSignature file = doesFileExist (dir </> file)
|
, return Nothing
|
||||||
|
)
|
||||||
|
isRepo = checkdir $ gitSignature $ ".git" </> "config"
|
||||||
|
isBareRepo = checkdir $ gitSignature "config"
|
||||||
|
<&&> doesDirectoryExist (dir </> "objects")
|
||||||
|
gitDirFile = do
|
||||||
|
c <- firstLine <$>
|
||||||
|
catchDefaultIO (readFile $ dir </> ".git") ""
|
||||||
|
return $ if gitdirprefix `isPrefixOf` c
|
||||||
|
then Just $ Local
|
||||||
|
{ gitdir = drop (length gitdirprefix) c
|
||||||
|
, worktree = Just dir
|
||||||
|
}
|
||||||
|
else Nothing
|
||||||
|
where
|
||||||
|
gitdirprefix = "gitdir: "
|
||||||
|
gitSignature file = doesFileExist $ dir </> file
|
||||||
|
|
||||||
newFrom :: RepoLocation -> IO Repo
|
newFrom :: RepoLocation -> IO Repo
|
||||||
newFrom l = return Repo
|
newFrom l = return Repo
|
||||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -17,6 +17,7 @@ git-annex (3.20120826) UNRELEASED; urgency=low
|
||||||
too long (and use relative path to minimise path to the control socket).
|
too long (and use relative path to minimise path to the control socket).
|
||||||
* migrate: Check content before generating the new key, to avoid generating
|
* migrate: Check content before generating the new key, to avoid generating
|
||||||
a key for corrupt data.
|
a key for corrupt data.
|
||||||
|
* Support repositories created with --separate-git-dir. Closes: #684405
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Mon, 27 Aug 2012 13:27:39 -0400
|
-- Joey Hess <joeyh@debian.org> Mon, 27 Aug 2012 13:27:39 -0400
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue