From aeaadb8eb802e9f8f806f358960f339a0b950f54 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 11 Sep 2023 14:21:36 -0400 Subject: [PATCH] improve warning message when unable to update export A misleading message was displayed in several cases. If the user has run eg: git config remote.push-win-remote.annex-tracking-branch 'adjusted/main(unlocked)' That is not supported, and now it will tell them it's not a valid configuration. A user reported doing that, but I don't know if it's a common point of confusion. If it is a common problem, a better message would be possible, or it could convert back from the adjusted branch to the actual branch. Sponsored-by: Graham Spencer on Patreon --- Command/Sync.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Command/Sync.hs b/Command/Sync.hs index 44edf2142a..5330a20ecb 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -985,8 +985,8 @@ seekExportContent o rs (currbranch, _) = or <$> forM rs go | maybe False (\o' -> operationMode o' == SatisfyMode) o = case remoteAnnexTrackingBranch (Remote.gitconfig r) of Nothing -> return False - Just b -> withdb r $ \db -> - cannotupdateexport r db (Just b) False + Just _ -> withdb r $ \db -> + cannotupdateexport r db Nothing False | not (maybe True pushOption o) = return False | not (remoteAnnexPush (Remote.gitconfig r)) = return False | otherwise = withdb r (go' r) @@ -1008,21 +1008,23 @@ seekExportContent o rs (currbranch, _) = or <$> forM rs go filteredtree <- Command.Export.filterExport r tree Command.Export.changeExport r db filteredtree Command.Export.fillExport r db filteredtree mtbcommitsha - | otherwise -> cannotupdateexport r db (Just b) False - _ -> cannotupdateexport r db (Just b) True + | otherwise -> cannotupdateexport r db Nothing False + (Nothing, _, _) -> cannotupdateexport r db (Just (Git.fromRef b ++ " does not exist")) True + (_, Nothing, _) -> cannotupdateexport r db (Just "no branch is currently checked out") True + (_, _, Nothing) -> cannotupdateexport r db (Just "tracking branch name is not valid") True withdb r a = bracket (Export.openDb (Remote.uuid r)) Export.closeDb (\db -> Export.writeLockDbWhile db (a db)) - cannotupdateexport r db mtb showwarning = do + cannotupdateexport r db mreason showwarning = do exported <- getExport (Remote.uuid r) when showwarning $ - maybe noop (warncannotupdateexport r mtb exported) currbranch + maybe noop (warncannotupdateexport r mreason exported) currbranch fillexistingexport r db (exportedTreeishes exported) Nothing - warncannotupdateexport r mtb exported currb = case mtb of + warncannotupdateexport r mreason exported currb = case mreason of Nothing -> inRepo (Git.Ref.tree currb) >>= \case Just currt | not (any (== currt) (exportedTreeishes exported)) -> showLongNote $ UnquotedString $ unwords @@ -1032,9 +1034,9 @@ seekExportContent o rs (currbranch, _) = or <$> forM rs go , "(Set " ++ gitconfig ++ " to enable it.)" ] _ -> noop - Just b -> showLongNote $ UnquotedString $ unwords + Just reason -> showLongNote $ UnquotedString $ unwords [ notupdating - , "because " ++ Git.fromRef b ++ " does not exist." + , "because " ++ reason ++ "." , "(As configured by " ++ gitconfig ++ ")" ] where