git-remote-annex: Fix error display on clone

cleanupInitialization gets run when an exception is thrown, so needs to
avoid throwing exceptions itself, as that would hide the error message
that the user needs to see.
This commit is contained in:
Joey Hess 2024-05-27 13:28:05 -04:00
parent a766475d14
commit 0975e792ea
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 15 additions and 11 deletions

View file

@ -1078,14 +1078,25 @@ specialRemoteFromUrl sab a = withTmpDir "journal" $ \tmpdir -> do
-- hooks, have to work around that by not initializing, and
-- delete the git bundle objects.
cleanupInitialization :: StartAnnexBranch -> Annex ()
cleanupInitialization sab = do
cleanupInitialization sab = void $ tryNonAsync $ do
case sab of
AnnexBranchExistedAlready _ -> noop
AnnexBranchCreatedEmpty r ->
whenM ((r ==) <$> Annex.Branch.getBranch) $ do
inRepo $ Git.Branch.delete Annex.Branch.fullname
indexfile <- fromRepo gitAnnexIndex
liftIO $ removeWhenExistsWith R.removeLink indexfile
-- When cloning failed and this is being
-- run as an exception is thrown, HEAD will
-- not be set to a valid value, which will
-- prevent deleting the git-annex branch.
-- But that's ok, git will delete the
-- repository it failed to clone into.
-- So skip deleting to avoid an ugly
-- message.
inRepo Git.Branch.currentUnsafe >>= \case
Nothing -> return ()
Just _ -> void $ tryNonAsync $
inRepo $ Git.Branch.delete Annex.Branch.fullname
ifM (Annex.Branch.hasSibling <&&> nonbuggygitversion)
( do
autoInitialize' (pure True) remoteList

View file

@ -6,13 +6,6 @@ It will be a safer implementation, will support incremental pushes, and
will be available to users who don't use datalad.
--[[Joey]]
---
This is implememented and working. Remaining todo list for it:
* When git clone is used with an annex:: url that is for a directory
special remote and is missing directory=, for example, it does
not display any useful error message. git fetch does, but it seems
git clone eats git-remote-annex stderr.
> [[done!]] --[[Joey]]
See also: [[git-remote-annex_web_special_remote_support]]