upgrade: Support an edge case upgrading a v5 direct mode repo where nothing had ever...
authorJoey Hess <joeyh@joeyh.name>
Tue, 24 Nov 2020 16:31:17 +0000 (12:31 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 24 Nov 2020 16:31:17 +0000 (12:31 -0400)
This commit was sponsored by Jack Hill on Patreon.

Annex/AdjustedBranch.hs
CHANGELOG
Upgrade/V5.hs
doc/bugs/v5_direct_upgrade_fail_with_annex.alwayscommit=false.mdwn

index 10715bc2276c3f8b5faf1e5f4042664ea72f3984..794493846c3940c725d0d26b3c617e08c971f350 100644 (file)
@@ -26,6 +26,7 @@ module Annex.AdjustedBranch (
        adjustBranch,
        adjustTree,
        adjustToCrippledFileSystem,
+       commitForAdjustedBranch,
        propigateAdjustedCommits,
        propigateAdjustedCommits',
        commitAdjustedTree,
@@ -334,14 +335,8 @@ adjustToCrippledFileSystem :: Annex ()
 adjustToCrippledFileSystem = do
        warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files."
        checkVersionSupported
-       whenM (isNothing <$> inRepo Git.Branch.current) $ do
-               cmode <- annexCommitMode <$> Annex.getGitConfig
-               void $ inRepo $ Git.Branch.commitCommand cmode
-                       [ Param "--quiet"
-                       , Param "--allow-empty"
-                       , Param "-m"
-                       , Param "commit before entering adjusted unlocked branch"
-                       ]
+       whenM (isNothing <$> inRepo Git.Branch.current) $
+               commitForAdjustedBranch []
        inRepo Git.Branch.current >>= \case
                Just currbranch -> case getAdjustment currbranch of
                        Just curradj | curradj == adj -> return ()
@@ -358,6 +353,22 @@ adjustToCrippledFileSystem = do
        adj = LinkAdjustment UnlockAdjustment
        failedenter = warning "Failed to enter adjusted branch!"
 
+{- Commit before entering adjusted branch. Only needs to be done
+ - when the current branch does not have any commits yet.
+ -
+ - If something is already staged, it will be committed, but otherwise
+ - an empty commit will be made.
+ -}
+commitForAdjustedBranch :: [CommandParam] -> Annex ()
+commitForAdjustedBranch ps = do
+       cmode <- annexCommitMode <$> Annex.getGitConfig
+       void $ inRepo $ Git.Branch.commitCommand cmode $
+               [ Param "--quiet"
+               , Param "--allow-empty"
+               , Param "-m"
+               , Param "commit before entering adjusted branch"
+               ] ++ ps
+
 setBasisBranch :: BasisBranch -> Ref -> Annex ()
 setBasisBranch (BasisBranch basis) new = 
        inRepo $ Git.Branch.update' basis new
index 620ee2ccb8171c44655fc3657f66154f6a1f0b45..b654e3585761e4e8a61caf357e664e8ad755e8c9 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -20,6 +20,8 @@ git-annex (8.20201117) UNRELEASED; urgency=medium
     locally.
   * Fix building without the torrent library.
     Thanks, Kyle Meyer.
+  * upgrade: Support an edge case upgrading a v5 direct mode repo
+    where nothing had ever been committed to the head branch.
 
  -- Joey Hess <id@joeyh.name>  Mon, 16 Nov 2020 09:38:32 -0400
 
index ead7636f271e099fbe7cdf3e79c37a328fc2ead3..98e60601f16379b4fa566c2a0dfd622e3a536722 100644 (file)
@@ -88,8 +88,13 @@ convertDirect = do
         - as does annex.thin. -}
        setConfig (annexConfig "thin") (boolConfig True)
        Direct.setIndirect
-       cur <- fromMaybe (error "Somehow no branch is checked out")
-               <$> inRepo Git.Branch.current
+       cur <- inRepo Git.Branch.current >>= \case
+               Just cur -> return cur
+               Nothing -> do
+                       -- Avoid running pre-commit hook.
+                       commitForAdjustedBranch [Param "--no-verify"]
+                       fromMaybe (giveup "Nothing is committed, and a commit failed; unable to proceed.") 
+                               <$> inRepo Git.Branch.current
        upgradeDirectWorkTree
        removeDirectCruft
        {- Create adjusted branch where all files are unlocked.
index 8989c3e9311d3d31735b8644f2494f05d76cdf32..65810f591854d4b0744bbead5635d89ad0f1773a 100644 (file)
@@ -36,5 +36,4 @@ and this sequence of commands:
 Note that lack of git-annex sync, which is why the branch
 never got created. The index file has the adds staged of course.
 
-So, fixing this unusual case needs the upgrade code to go ahead and commit
-the staged index first. 
+> [[fixed|done]] --[[Joey]]