]> dgit.raspbian.org Git - git-annex.git/commitdiff
Avoid converting .git file in a worktree or submodule to a symlink when the repositor...
authorJoey Hess <joeyh@joeyh.name>
Mon, 9 Mar 2020 18:45:14 +0000 (14:45 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 9 Mar 2020 18:54:14 +0000 (14:54 -0400)
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
Annex/Init.hs
CHANGELOG
doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git.mdwn
doc/bugs/running_git_annex_commands_in_worktree_of_a_non-git-annex_repo_changes_the_.git/comment_1_d5d8754af32ac45cd6303805bfe99911._comment [new file with mode: 0644]

index 63d2c2535b2f4cbae4cc752e21527c871388f262..e0a5a33e201ffeae33b5e77bbb61da5037882f7a 100644 (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
index ec6b8fc4222e932eb99623f79fa1450e1368a702..5acfccf7f6d765c922406e91bcfd91b37e31e9c3 100644 (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
index 1d8ce603a58fc7d7bb04e71b927d718dc3353e75..1a5a12dc945749a1ca3bde09371f59913a84c3c7 100644 (file)
--- 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: <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
 
index 990de91f62caf1e0536ad3f4a6eabcc308300273..a5cb961747771c2b9398f792bdb95b922577fdcb 100644 (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]]
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 (file)
index 0000000..bcf902a
--- /dev/null
@@ -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.
+"""]]