upgrade: Support an edge case upgrading a v5 direct mode repo where nothing had ever been committed to the head branch

This commit was sponsored by Jack Hill on Patreon.
This commit is contained in:
Joey Hess 2020-11-24 12:31:17 -04:00
parent 14155bcebe
commit 88cef18fac
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 29 additions and 12 deletions

View file

@ -26,6 +26,7 @@ module Annex.AdjustedBranch (
adjustBranch, adjustBranch,
adjustTree, adjustTree,
adjustToCrippledFileSystem, adjustToCrippledFileSystem,
commitForAdjustedBranch,
propigateAdjustedCommits, propigateAdjustedCommits,
propigateAdjustedCommits', propigateAdjustedCommits',
commitAdjustedTree, commitAdjustedTree,
@ -334,14 +335,8 @@ adjustToCrippledFileSystem :: Annex ()
adjustToCrippledFileSystem = do adjustToCrippledFileSystem = do
warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files." warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files."
checkVersionSupported checkVersionSupported
whenM (isNothing <$> inRepo Git.Branch.current) $ do whenM (isNothing <$> inRepo Git.Branch.current) $
cmode <- annexCommitMode <$> Annex.getGitConfig commitForAdjustedBranch []
void $ inRepo $ Git.Branch.commitCommand cmode
[ Param "--quiet"
, Param "--allow-empty"
, Param "-m"
, Param "commit before entering adjusted unlocked branch"
]
inRepo Git.Branch.current >>= \case inRepo Git.Branch.current >>= \case
Just currbranch -> case getAdjustment currbranch of Just currbranch -> case getAdjustment currbranch of
Just curradj | curradj == adj -> return () Just curradj | curradj == adj -> return ()
@ -358,6 +353,22 @@ adjustToCrippledFileSystem = do
adj = LinkAdjustment UnlockAdjustment adj = LinkAdjustment UnlockAdjustment
failedenter = warning "Failed to enter adjusted branch!" 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 -> Ref -> Annex ()
setBasisBranch (BasisBranch basis) new = setBasisBranch (BasisBranch basis) new =
inRepo $ Git.Branch.update' basis new inRepo $ Git.Branch.update' basis new

View file

@ -20,6 +20,8 @@ git-annex (8.20201117) UNRELEASED; urgency=medium
locally. locally.
* Fix building without the torrent library. * Fix building without the torrent library.
Thanks, Kyle Meyer. 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 -- Joey Hess <id@joeyh.name> Mon, 16 Nov 2020 09:38:32 -0400

View file

@ -88,7 +88,12 @@ convertDirect = do
- as does annex.thin. -} - as does annex.thin. -}
setConfig (annexConfig "thin") (boolConfig True) setConfig (annexConfig "thin") (boolConfig True)
Direct.setIndirect Direct.setIndirect
cur <- fromMaybe (error "Somehow no branch is checked out") 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 <$> inRepo Git.Branch.current
upgradeDirectWorkTree upgradeDirectWorkTree
removeDirectCruft removeDirectCruft

View file

@ -36,5 +36,4 @@ and this sequence of commands:
Note that lack of git-annex sync, which is why the branch Note that lack of git-annex sync, which is why the branch
never got created. The index file has the adds staged of course. 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 > [[fixed|done]] --[[Joey]]
the staged index first.