From cbb4a2bf86d0bd0797e497534d028af3eb9865f8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 16 Sep 2025 13:22:14 -0400 Subject: [PATCH] improve error message when SETCREDS overwrites git-annex config That is not allowed, so it's not a bug in git-annex when it happens and instead tell the special remote developer how it's messed up. Note that currently only Remote.External can overwrite the parsed remote config with a PassedThrough value. PassedThrough values are otherwise only generated for configs that are not parsed by the remote config parser. Sponsored-by: Joshua Antonishen --- Annex/SpecialRemote/Config.hs | 24 +++++++++++++------ ..._7ec2d0de7c0b90f05475b86148982197._comment | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 doc/todo/encrypt_only_the_credentials/comment_8_7ec2d0de7c0b90f05475b86148982197._comment diff --git a/Annex/SpecialRemote/Config.hs b/Annex/SpecialRemote/Config.hs index 5f9d6db831..925b7e837c 100644 --- a/Annex/SpecialRemote/Config.hs +++ b/Annex/SpecialRemote/Config.hs @@ -206,13 +206,23 @@ getRemoteConfigValue :: HasCallStack => Typeable v => RemoteConfigField -> Parse getRemoteConfigValue f (ParsedRemoteConfig m _) = case M.lookup f m of Just (RemoteConfigValue v) -> case cast v of Just v' -> Just v' - Nothing -> error $ unwords - [ "getRemoteConfigValue" - , fromProposedAccepted f - , "found value of unexpected type" - , show (typeOf v) ++ "." - , "This is a bug in git-annex!" - ] + Nothing -> case cast v :: Maybe PassedThrough of + -- Handle the case where an external special remote + -- tries to SETCONFIG a value belonging to git-annex, + -- resulting in a PassedThrough type being stored. + Just _ -> error $ unwords + [ "Special remote config " + , fromProposedAccepted f + , "has been overwritten by SETCONFIG." + , "This is not supported." + ] + Nothing -> error $ unwords + [ "getRemoteConfigValue" + , fromProposedAccepted f + , "found value of unexpected type" + , show (typeOf v) ++ "." + , "This is a bug in git-annex!" + ] Nothing -> Nothing {- Gets all fields that remoteConfigRestPassthrough matched. -} diff --git a/doc/todo/encrypt_only_the_credentials/comment_8_7ec2d0de7c0b90f05475b86148982197._comment b/doc/todo/encrypt_only_the_credentials/comment_8_7ec2d0de7c0b90f05475b86148982197._comment new file mode 100644 index 0000000000..65c6774e52 --- /dev/null +++ b/doc/todo/encrypt_only_the_credentials/comment_8_7ec2d0de7c0b90f05475b86148982197._comment @@ -0,0 +1,24 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 8""" + date="2025-09-16T16:57:11Z" + content=""" +SETCONFIG is limited to setting the external program's configuration, +not to reaching inside git-annex and setting its own configuration. +The docs say that, but could perhaps be more clear. + +I have improved the error message. + +git-annex sets up encryption for the remote based on the encryption= and +encryptonlycreds= settings before it ever starts up the external program. +That would need to change in order to support this. + +But I'm also doubtful it would be a good idea to support SETCONFIG +of any of the things git-annex uses for encryption, chunking, etc. +It's essentially monkey-patching git-annex from the external program. +Some changes to git-annex's configs could lead to very unexpected behavior. + +If you really need the ability to turn on onlyencryptcreds by default +with your special remote, there will need to be some other way implemented +to do it. Please open a new todo about that. +"""]]