From d930a2035cf2be0ffa92443375a79b338fed4272 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 9 Mar 2020 14:45:14 -0400 Subject: [PATCH] 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. --- Annex/Fixup.hs | 33 ++++++++----------- Annex/Init.hs | 7 ++++ CHANGELOG | 4 +-- ...a_non-git-annex_repo_changes_the_.git.mdwn | 1 + ..._d5d8754af32ac45cd6303805bfe99911._comment | 14 ++++++++ 5 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git/comment_1_d5d8754af32ac45cd6303805bfe99911._comment diff --git a/Annex/Fixup.hs b/Annex/Fixup.hs index 63d2c2535b..e0a5a33e20 100644 --- a/Annex/Fixup.hs +++ b/Annex/Fixup.hs @@ -1,6 +1,6 @@ {- git-annex repository fixups - - - Copyright 2013-2019 Joey Hess + - Copyright 2013-2020 Joey Hess - - 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 diff --git a/Annex/Init.hs b/Annex/Init.hs index ec6b8fc422..5acfccf7f6 100644 --- a/Annex/Init.hs +++ b/Annex/Init.hs @@ -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 diff --git a/CHANGELOG b/CHANGELOG index 1d8ce603a5..1a5a12dc94 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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: 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 Thu, 27 Feb 2020 00:44:11 -0400 diff --git a/doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git.mdwn b/doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git.mdwn index 990de91f62..a5cb961747 100644 --- a/doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git.mdwn +++ b/doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git.mdwn @@ -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]] diff --git a/doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git/comment_1_d5d8754af32ac45cd6303805bfe99911._comment b/doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git/comment_1_d5d8754af32ac45cd6303805bfe99911._comment new file mode 100644 index 0000000000..bcf902a17c --- /dev/null +++ b/doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git/comment_1_d5d8754af32ac45cd6303805bfe99911._comment @@ -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. +"""]]