From c94a5d86b80dd06a018689da551012bf7d608dec Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 15 Jul 2014 14:27:43 -0400 Subject: sync: Fix git sync with local git remotes even when they don't have an annex.uuid set. Catch an exception when ensureInitialized is run in a non-initted repository. In this case, just read the git config, so that the Git.Repo object is not LocalUnknown, which is what is used to represent remotes on eg, drives that are not connected. The assistant already got this right, and like with the assistant, this causes an implicit git-annex init of the local remote on the second sync, once the git-annex branch has been pushed to it. See this comment for more analysis: http://git-annex.branchable.com/todo/Recovering_from_a_bad_sync/#comment-64e469a2c1969829ee149cbb41b1c138 This commit was sponsored by jscit. --- Remote/Git.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Remote/Git.hs') diff --git a/Remote/Git.hs b/Remote/Git.hs index 5dcd3bf15..6308f5cd6 100644 --- a/Remote/Git.hs +++ b/Remote/Git.hs @@ -191,20 +191,11 @@ tryGitConfigRead r | Git.repoIsHttp r = store geturlconfig | Git.GCrypt.isEncrypted r = handlegcrypt =<< getConfigMaybe (remoteConfig r "uuid") | Git.repoIsUrl r = return r - | otherwise = store $ safely $ do - s <- Annex.new r - Annex.eval s $ do - Annex.BranchState.disableUpdate - ensureInitialized - Annex.getState Annex.repo + | otherwise = store $ liftIO $ + readlocalannexconfig `catchNonAsync` (const $ Git.Config.read r) where haveconfig = not . M.null . Git.config - -- Reading config can fail due to IO error or - -- for other reasons; catch all possible exceptions. - safely a = either (const $ return r) return - =<< liftIO (try a :: IO (Either SomeException Git.Repo)) - pipedconfig cmd params = do v <- Git.Config.fromPipe r cmd params case v of @@ -283,6 +274,15 @@ tryGitConfigRead r Just v -> store $ liftIO $ setUUID r $ genUUIDInNameSpace gCryptNameSpace v + {- Throws an exception if the remote is not already initialied + - or cannot be automatically initialized. -} + readlocalannexconfig = do + s <- Annex.new r + Annex.eval s $ do + Annex.BranchState.disableUpdate + ensureInitialized + Annex.getState Annex.repo + {- Checks if a given remote has the content for a key inAnnex. - If the remote cannot be accessed, or if it cannot determine - whether it has the content, returns a Left error message. -- cgit v1.2.3