auto-init autoenable=yes

Try to enable special remotes configured with autoenable=yes when git-annex
auto-initialization happens in a new clone of an existing repo. Previously,
git-annex init had to be explicitly run to enable them. That was a bit of a
wart of a special case for users to need to keep in mind.

Special remotes cannot display anything when autoenabled this way, to avoid
interfering with the output of git-annex query commands.

Any error messages will be hidden, and if it fails, nothing is displayed.
The user will realize the remote isn't enable when they try to use it,
and can run git-annex init manually then to try the autoenable again and
see what failed.

That seems like a reasonable approach, and it's less complicated than
communicating something across a pipe in order to display it as a side
message. Other reason not to do that is that, if the first command the
user runs is one like git-annex find that has machine readable output,
any message about autoenable failing would need to not be displayed anyway.
So better to not display a failure message ever, for consistency.

(Had to split out Remote.List.Util to avoid an import cycle.)
This commit is contained in:
Joey Hess 2020-05-27 11:54:39 -04:00
parent 731815891d
commit 484a74f073
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
16 changed files with 105 additions and 37 deletions

View file

@ -16,7 +16,7 @@ import Types.Transfer
import Logs.Location
import Assistant.DaemonStatus
import qualified Remote
import Remote.List
import Remote.List.Util
import qualified Git.Remote.Remove
import Logs.Trust
import qualified Annex
@ -35,7 +35,7 @@ disableRemote uuid = do
<$> liftAnnex (Remote.remoteFromUUID uuid)
liftAnnex $ do
inRepo $ Git.Remote.Remove.remove (Remote.name remote)
void $ remoteListRefresh
remotesChanged
updateSyncRemotes
return remote

View file

@ -13,7 +13,7 @@ import Assistant.Common
import Assistant.Ssh
import qualified Types.Remote as R
import qualified Remote
import Remote.List
import Remote.List.Util
import qualified Remote.Rsync as Rsync
import qualified Remote.GCrypt as GCrypt
import qualified Git
@ -46,7 +46,7 @@ makeSshRemote sshdata = maker (sshRepoName sshdata) (genSshUrl sshdata)
addRemote :: Annex RemoteName -> Annex Remote
addRemote a = do
name <- a
void remoteListRefresh
remotesChanged
maybe (error "failed to add remote") return
=<< Remote.byName (Just name)
@ -174,7 +174,9 @@ previouslyUsedCredPair
-> (Remote -> Bool)
-> Annex (Maybe CredPair)
previouslyUsedCredPair getstorage remotetype criteria =
getM fromstorage =<< filter criteria . filter sametype <$> remoteList
getM fromstorage
=<< filter criteria . filter sametype
<$> Remote.remoteList
where
sametype r = R.typename (R.remotetype r) == R.typename remotetype
fromstorage r = do

View file

@ -22,8 +22,8 @@ import qualified Git
import qualified Git.Command
import qualified Remote
import qualified Types.Remote as Remote
import qualified Remote.List as Remote
import qualified Annex.Branch
import Remote.List.Util
import Annex.UUID
import Annex.TaggedPush
import Annex.Ssh
@ -268,7 +268,7 @@ changeSyncFlag r enabled = do
repo <- Remote.getRepo r
let key = Config.remoteAnnexConfig repo "sync"
Config.setConfig key (boolConfig enabled)
void Remote.remoteListRefresh
remotesChanged
updateExportTreeFromLogAll :: Assistant ()
updateExportTreeFromLogAll = do

View file

@ -18,7 +18,7 @@ import Logs.Trust
import Logs.PreferredContent
import Logs.Group
import Logs.NumCopies
import Remote.List (remoteListRefresh)
import Remote.List.Util
import qualified Git.LsTree as LsTree
import Git.Types
import Git.FilePath
@ -60,7 +60,7 @@ type Configs = S.Set (RawFilePath, Sha)
configFilesActions :: [(RawFilePath, Assistant ())]
configFilesActions =
[ (uuidLog, void $ liftAnnex uuidDescMapLoad)
, (remoteLog, void $ liftAnnex remoteListRefresh)
, (remoteLog, void $ liftAnnex remotesChanged)
, (trustLog, void $ liftAnnex trustMapLoad)
, (groupLog, void $ liftAnnex groupMapLoad)
, (numcopiesLog, void $ liftAnnex globalNumCopiesLoad)

View file

@ -25,7 +25,7 @@ import qualified Remote.S3 as S3
#endif
import qualified Remote
import qualified Types.Remote as Remote
import qualified Remote.List as Remote
import Remote.List.Util
import Logs.UUID
import Logs.Group
import Logs.PreferredContent
@ -116,7 +116,7 @@ setRepoConfig uuid mremote oldc newc = do
, Param $ T.unpack $ repoName oldc
, Param name
]
void Remote.remoteListRefresh
remotesChanged
liftAssistant updateSyncRemotes
when associatedDirectoryChanged $ case repoAssociatedDirectory newc of
Nothing -> noop
@ -309,7 +309,7 @@ getUpgradeRepositoryR r = go =<< liftAnnex (repoIdRemote r)
setConfig
(remoteAnnexConfig repo "ignore")
(Git.Config.boolConfig False)
liftAnnex $ void Remote.remoteListRefresh
liftAnnex remotesChanged
liftAssistant updateSyncRemotes
liftAssistant $ syncRemote rmt
redirect DashboardR

View file

@ -14,7 +14,7 @@ import Assistant.DaemonStatus
import Assistant.WebApp.Notifications
import qualified Remote
import qualified Types.Remote as Remote
import Remote.List (remoteListRefresh)
import Remote.List.Util
import Annex.UUID (getUUID)
import Logs.Remote
import Logs.Trust
@ -242,7 +242,7 @@ getRepositoriesReorderR = do
when (Remote.cost r /= newcost) $ do
repo <- Remote.getRepo r
setRemoteCost repo newcost
void remoteListRefresh
remotesChanged
fromjs = fromMaybe (RepoUUID NoUUID) . readish . T.unpack
reorderCosts :: Remote -> [Remote] -> [(Remote, Cost)]