From 5db79339a14038c67a398f392378a314c07baf39 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 21 Oct 2019 11:04:24 -0400 Subject: [PATCH] init: Fix a failure when used in a submodule on a crippled filesystem. When the submodule's parent repo has an adjusted unlocked branch, it gets cloned by git, but git checks out master. git annex init then fails because it wants to enter the adjusted branch, but: adjusted branch adjusted/master(unlocked) already exists. Aborting because that branch may have changes that have not yet reached master Note that init actually then exits 0, leaving master checked out. This could also happen, absent submodules, if the parent repo has an adjusted unlocked branch, but it is not checked out. In the more common case where that branch is checked out, the clone uses the same branch, so no problem. The choices to fix this: * Init could delete the existing adjusted branch, and re-adjust. But then running init inside an adjusted branch on a crippled filesystem would lose any changes that have not been synced back to master. * Init could sync any changes back to master, but that would be very surprising behavior for it. * Init could simply check out the existing adjusted branch. If the branch is diverged from master, well, sync will sort that out later. This mirrors the behavior of cloning a repo that has an adjusted branch checked out that has not yet been synced back to master. Picked this choice. --- Annex/AdjustedBranch.hs | 19 ++++++++++++++++--- CHANGELOG | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs index cc041e5022..597574fda2 100644 --- a/Annex/AdjustedBranch.hs +++ b/Annex/AdjustedBranch.hs @@ -227,15 +227,28 @@ adjustToCrippledFileSystem :: Annex () adjustToCrippledFileSystem = do warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files." checkVersionSupported - whenM (isNothing <$> originalBranch) $ + whenM (isNothing <$> inRepo Git.Branch.current) $ void $ inRepo $ Git.Branch.commitCommand Git.Branch.AutomaticCommit [ Param "--quiet" , Param "--allow-empty" , Param "-m" , Param "commit before entering adjusted unlocked branch" ] - unlessM (enterAdjustedBranch (LinkAdjustment UnlockAdjustment)) $ - warning "Failed to enter adjusted branch!" + inRepo Git.Branch.current >>= \case + Just currbranch -> case getAdjustment currbranch of + Just curradj | curradj == adj -> return () + _ -> do + let adjbranch = originalToAdjusted currbranch adj + ifM (inRepo (Git.Ref.exists $ adjBranch adjbranch)) + ( unlessM (checkoutAdjustedBranch adjbranch []) $ + failedenter + , unlessM (enterAdjustedBranch adj) $ + failedenter + ) + Nothing -> failedenter + where + adj = LinkAdjustment UnlockAdjustment + failedenter = warning "Failed to enter adjusted branch!" setBasisBranch :: BasisBranch -> Ref -> Annex () setBasisBranch (BasisBranch basis) new = diff --git a/CHANGELOG b/CHANGELOG index c81b58ba6e..296362f1a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +git-annex (7.20191018) UNRELEASED; urgency=medium + + * init: Fix a failure when used in a submodule on a crippled filesystem. + + -- Joey Hess Mon, 21 Oct 2019 11:01:06 -0400 + git-annex (7.20191017) upstream; urgency=medium * initremote: Added --sameas option, allows for two special remotes that