Support working trees set up by git-worktree.

Support working trees set up by git-worktree, by setting up some symlinks
such that git-annex links work right.

Also improved support for repositories created with --separate-git-dir.
At least recent git makes a .git file for those (older may have used a
symlink?), so that also needs to be converted to a symlink.

This commit was sponsored by Nick Piper on Patreon.
This commit is contained in:
Joey Hess 2018-07-18 14:25:03 -04:00
parent ac5680f6f5
commit 081f8e57c6
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 81 additions and 18 deletions

View file

@ -207,10 +207,19 @@ checkForRepo dir =
( return $ Just $ LocalUnknown dir
, return Nothing
)
isRepo = checkdir $ gitSignature $ ".git" </> "config"
isRepo = checkdir $
gitSignature (".git" </> "config")
<||>
-- A git-worktree lacks .git/config, but has .git/commondir.
-- (Normally the .git is a file, not a symlink, but it can
-- be converted to a symlink and git will still work;
-- this handles that case.)
gitSignature (".git" </> "gitdir")
isBareRepo = checkdir $ gitSignature "config"
<&&> doesDirectoryExist (dir </> "objects")
gitDirFile = do
-- git-submodule, git-worktree, and --separate-git-dir
-- make .git be a file pointing to the real git directory.
c <- firstLine <$>
catchDefaultIO "" (readFile $ dir </> ".git")
return $ if gitdirprefix `isPrefixOf` c