diff --git a/Annex/Branch.hs b/Annex/Branch.hs index 7cd86c5815..7411e70104 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -38,6 +38,7 @@ import Annex.Index import qualified Git import qualified Git.Command import qualified Git.Ref +import qualified Git.RefLog import qualified Git.Sha import qualified Git.Branch import qualified Git.UnionMerge @@ -205,7 +206,13 @@ getRaw :: FilePath -> Annex String getRaw = getRef fullname getHistorical :: RefDate -> FilePath -> Annex String -getHistorical date = getRef (Git.Ref.dateRef fullname date) +getHistorical date file = + -- This check avoids some ugly error messages when the reflog + -- is empty. + ifM (null <$> inRepo (Git.RefLog.get' [Param "-n1"] fullname)) + ( error ("No reflog for " ++ fromRef fullname) + , getRef (Git.Ref.dateRef fullname date) file + ) getRef :: Ref -> FilePath -> Annex String getRef ref file = withIndex $ decodeBS <$> catFile ref file diff --git a/Git/RefLog.hs b/Git/RefLog.hs index f3a9dad38e..7c20047ad7 100644 --- a/Git/RefLog.hs +++ b/Git/RefLog.hs @@ -14,9 +14,14 @@ import Git.Sha {- Gets the reflog for a given branch. -} get :: Branch -> Repo -> IO [Sha] -get b = mapMaybe extractSha . lines <$$> pipeReadStrict - [ Param "log" - , Param "-g" - , Param "--format=%H" - , Param (fromRef b) - ] +get = get' [] + +get' :: [CommandParam] -> Branch -> Repo -> IO [Sha] +get' ps b = mapMaybe extractSha . lines <$$> pipeReadStrict ps' + where + ps' = + [ Param "log" + , Param "-g" + , Param "--format=%H" + , Param (fromRef b) + ] ++ ps diff --git a/debian/changelog b/debian/changelog index 7add96dac2..79810d546f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,8 @@ git-annex (5.20150318) UNRELEASED; urgency=medium * --auto is no longer a global option; only get, drop, and copy accept it. (Not a behavior change unless you were passing it to a command that ignored it.) + * Improve error message when --in @date is used and there is no + reflog for the git-annex branch. -- Joey Hess Thu, 19 Mar 2015 17:05:32 -0400 diff --git a/doc/bugs/Using_date_matching_options_gives_scary_error_messaes_on_empty_reflog.mdwn b/doc/bugs/Using_date_matching_options_gives_scary_error_messaes_on_empty_reflog.mdwn index 487849f782..006de83004 100644 --- a/doc/bugs/Using_date_matching_options_gives_scary_error_messaes_on_empty_reflog.mdwn +++ b/doc/bugs/Using_date_matching_options_gives_scary_error_messaes_on_empty_reflog.mdwn @@ -31,3 +31,5 @@ git-annex: fd:9: hFlush: resource vanished (Broken pipe) # End of transcript or log. """]] + +> [[fixed|done]] --[[Joey]]