From 434a8098037574ddd83e09bbf82a9d5b27181b8e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 2 Jan 2014 13:12:32 -0400 Subject: Remotes can now be made read-only, by setting remote..annex-readonly --- Assistant/Sync.hs | 3 ++- Command/Sync.hs | 4 +++- Remote/Helper/ReadOnly.hs | 29 +++++++++++++++++++++++++++++ Remote/List.hs | 3 ++- Types/GitConfig.hs | 2 ++ debian/changelog | 1 + doc/git-annex.mdwn | 6 ++++++ 7 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 Remote/Helper/ReadOnly.hs diff --git a/Assistant/Sync.hs b/Assistant/Sync.hs index f7656f52d..adbe41350 100644 --- a/Assistant/Sync.hs +++ b/Assistant/Sync.hs @@ -123,7 +123,8 @@ reconnectRemotes notifypushes rs = void $ do pushToRemotes :: Bool -> [Remote] -> Assistant [Remote] pushToRemotes notifypushes remotes = do now <- liftIO getCurrentTime - syncAction remotes (pushToRemotes' now notifypushes) + let remotes' = filter (not . remoteAnnexReadOnly . Remote.gitconfig) remotes + syncAction remotes' (pushToRemotes' now notifypushes) pushToRemotes' :: UTCTime -> Bool -> [Remote] -> Assistant [Remote] pushToRemotes' now notifypushes remotes = do (g, branch, u) <- liftAnnex $ do diff --git a/Command/Sync.hs b/Command/Sync.hs index 14c79e99d..38a6a5c6a 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -203,7 +203,9 @@ pushRemote :: Remote -> Maybe Git.Ref -> CommandStart pushRemote _remote Nothing = stop pushRemote remote (Just branch) = go =<< needpush where - needpush = anyM (newer remote) [syncBranch branch, Annex.Branch.name] + needpush + | remoteAnnexReadOnly (Types.Remote.gitconfig remote) = return False + | otherwise = anyM (newer remote) [syncBranch branch, Annex.Branch.name] go False = stop go True = do showStart "push" (Remote.name remote) diff --git a/Remote/Helper/ReadOnly.hs b/Remote/Helper/ReadOnly.hs new file mode 100644 index 000000000..cd92a083c --- /dev/null +++ b/Remote/Helper/ReadOnly.hs @@ -0,0 +1,29 @@ +{- Adds readonly support to remotes. + - + - Copyright 2013 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Remote.Helper.ReadOnly (adjustReadOnly) where + +import Common.Annex +import Types.Remote + +{- Adds support for read-only remotes, by replacing the + - methods that write to a remote with dummies that fail. + - + - Note that disabling git pushes to remotes is not handled here. + -} +adjustReadOnly :: Remote -> Remote +adjustReadOnly r + | remoteAnnexReadOnly (gitconfig r) = r + { storeKey = \_ _ _ -> failbool + , removeKey = \_ -> failbool + , repairRepo = Nothing + } + | otherwise = r + where + failbool = do + warning "this remote is readonly" + return False diff --git a/Remote/List.hs b/Remote/List.hs index d01d23944..cc7019850 100644 --- a/Remote/List.hs +++ b/Remote/List.hs @@ -18,6 +18,7 @@ import Types.Remote import Types.GitConfig import Annex.UUID import Remote.Helper.Hooks +import Remote.Helper.ReadOnly import qualified Git import qualified Git.Config @@ -89,7 +90,7 @@ remoteGen m t r = do let gc = extractRemoteGitConfig g (Git.repoDescribe r) let c = fromMaybe M.empty $ M.lookup u m mrmt <- generate t r u c gc - return $ addHooks <$> mrmt + return $ adjustReadOnly . addHooks <$> mrmt {- Updates a local git Remote, re-reading its git config. -} updateRemote :: Remote -> Annex (Maybe Remote) diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index afb40a795..fad5127ed 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -97,6 +97,7 @@ data RemoteGitConfig = RemoteGitConfig , remoteAnnexCostCommand :: Maybe String , remoteAnnexIgnore :: Bool , remoteAnnexSync :: Bool + , remoteAnnexReadOnly :: Bool , remoteAnnexTrustLevel :: Maybe String , remoteAnnexStartCommand :: Maybe String , remoteAnnexStopCommand :: Maybe String @@ -124,6 +125,7 @@ extractRemoteGitConfig r remotename = RemoteGitConfig , remoteAnnexCostCommand = notempty $ getmaybe "cost-command" , remoteAnnexIgnore = getbool "ignore" False , remoteAnnexSync = getbool "sync" True + , remoteAnnexReadOnly = getbool "readonly" False , remoteAnnexTrustLevel = notempty $ getmaybe "trustlevel" , remoteAnnexStartCommand = notempty $ getmaybe "start-command" , remoteAnnexStopCommand = notempty $ getmaybe "stop-command" diff --git a/debian/changelog b/debian/changelog index 353c5361d..ba7d5686f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,7 @@ git-annex (5.20131231) UNRELEASED; urgency=medium * Avoid looping if long-running git cat-file or git hash-object crashes and keeps crashing when restarted. * Assistant: Remove stale MERGE_HEAD files in lockfile cleanup. + * Remotes can now be made read-only, by setting remote..annex-readonly -- Joey Hess Tue, 31 Dec 2013 13:41:18 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index da9e021da..27d4df93a 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -1275,6 +1275,12 @@ Here are all the supported configuration settings. If set to `false`, prevents git-annex sync (and the git-annex assistant) from syncing with this remote. +* `remote..annex-readonly` + + If set to `true`, prevents git-annex from making changes to a remote. + This both prevents git-annex sync from pushing changes, and prevents + storing or removing files from read-only remote. + * `remote..annexUrl` Can be used to specify a different url than the regular `remote..url` -- cgit v1.2.3