Avoid converting .git file in a worktree or submodule to a symlink when the repository is not a git-annex repository.

This means it will still be a .git file when git-annex init runs. That's
ok, the repo probably contains no annexed objects yet, and even if it does,
git-annex init does not care if symlinks in the worktree don't point to the
objects.

I made init, at the end, run the conversion code. Not really necessary
because the next git-annex command could do it just as well. But, this
avoids commands that don't normally write to the repo needing to write to
it, which might avoid some problem or other, and seems worth avoiding
generally.
This commit is contained in:
Joey Hess 2020-03-09 14:45:14 -04:00
parent c0a981cb0e
commit d930a2035c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 37 additions and 22 deletions

View file

@ -1,6 +1,6 @@
{- git-annex repository fixups
-
- Copyright 2013-2019 Joey Hess <id@joeyh.name>
- Copyright 2013-2020 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -12,8 +12,6 @@ module Annex.Fixup where
import Git.Types
import Git.Config
import Types.GitConfig
import Config.Files
import qualified Git
import Utility.Path
import Utility.SafeCommand
import Utility.Directory
@ -86,24 +84,21 @@ fixupDirect r = r
- into a symlink. But we don't need too, since the repo will use adjusted
- unlocked branches.
-
- Before making any changes, check if there's a .noannex file
- in the repo. If that file will prevent git-annex from being used,
- there's no need to fix up the repository.
- Don't do any of this if the repo has not been initialized for git-annex
- use yet.
-}
fixupUnusualRepos :: Repo -> GitConfig -> IO Repo
fixupUnusualRepos r@(Repo { location = l@(Local { worktree = Just w, gitdir = d }) }) c
| needsSubmoduleFixup r = ifM notnoannex
( do
when (coreSymlinks c) $
(replacedotgit >> unsetcoreworktree)
`catchNonAsync` \_e -> hPutStrLn stderr
"warning: unable to convert submodule to form that will work with git-annex"
return $ r'
{ config = M.delete "core.worktree" (config r)
}
, return r
)
| otherwise = ifM (needsGitLinkFixup r <&&> notnoannex)
| isNothing (annexVersion c) = return r
| needsSubmoduleFixup r = do
when (coreSymlinks c) $
(replacedotgit >> unsetcoreworktree)
`catchNonAsync` \_e -> hPutStrLn stderr
"warning: unable to convert submodule to form that will work with git-annex"
return $ r'
{ config = M.delete "core.worktree" (config r)
}
| otherwise = ifM (needsGitLinkFixup r)
( do
when (coreSymlinks c) $
(replacedotgit >> worktreefixup)
@ -144,8 +139,6 @@ fixupUnusualRepos r@(Repo { location = l@(Local { worktree = Just w, gitdir = d
r'
| coreSymlinks c = r { location = l { gitdir = dotgit } }
| otherwise = r
notnoannex = isNothing <$> noAnnexFileContent (fmap fromRawFilePath (Git.repoWorkTree r))
fixupUnusualRepos r _ = return r
needsSubmoduleFixup :: Repo -> Bool

View file

@ -34,6 +34,7 @@ import Annex.Version
import Annex.Difference
import Annex.UUID
import Annex.WorkTree
import Annex.Fixup
import Config
import Config.Files
import Config.Smudge
@ -129,6 +130,7 @@ initialize' mversion = checkCanInitialize $ do
)
propigateSecureHashesOnly
createInodeSentinalFile False
fixupUnusualReposAfterInit
uninitialize :: Annex ()
uninitialize = do
@ -280,3 +282,8 @@ propigateSecureHashesOnly :: Annex ()
propigateSecureHashesOnly =
maybe noop (setConfig "annex.securehashesonly" . fromConfigValue)
=<< getGlobalConfig "annex.securehashesonly"
fixupUnusualReposAfterInit :: Annex ()
fixupUnusualReposAfterInit = do
gc <- Annex.getGitConfig
void $ inRepo $ \r -> fixupUnusualRepos r gc

View file

@ -20,8 +20,8 @@ git-annex (8.20200227) UNRELEASED; urgency=medium
* git-annex config: Only allow configs be set that are ones git-annex actually
supports reading from repo-global config, to avoid confusion.
* Linux standalone: Use md5sum to shorten paths in .cache/git-annex/locales
* Fix a problem in auto-upgrade of a clone to v8 that caused a
message "fatal: <path> is outside repository".
* Avoid converting .git file in a worktree or submodule to a symlink
when the repository is not a git-annex repository.
-- Joey Hess <id@joeyh.name> Thu, 27 Feb 2020 00:44:11 -0400

View file

@ -65,3 +65,4 @@ Linux ip-172-31-80-211.ec2.internal 4.14.171-136.231.amzn2.x86_64 #1 SMP Thu Feb
### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
> [[fixed|done]] --[[Joey]]

View file

@ -0,0 +1,14 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2020-03-09T18:31:46Z"
content="""
Hmm, fixupUnusualRepos was earlier changed to check for .noannex
files, and avoid doing anything. Didn't think big enough I suppose.
I agree, git-annex should not be hacking on git repos that have not had
git-annex initialized in them yet. Luckily all the hacks are about making
.git files into symlinks so links to annexed files work, so it will be ok
for the .git file to remain unconverted until the end of git-annex init,
or even by a subsequent git-annex command.
"""]]