From afe0cc0bb4fbe3876c35462dece4670617263877 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 21 Oct 2013 16:19:00 -0400 Subject: corrupt branch resetting (but not yet reflog walking) --- git-recover-repository.hs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'git-recover-repository.hs') diff --git a/git-recover-repository.hs b/git-recover-repository.hs index 66b1708f8..3a002e72c 100644 --- a/git-recover-repository.hs +++ b/git-recover-repository.hs @@ -16,6 +16,7 @@ import Common import qualified Git.CurrentRepo import qualified Git.RecoverRepository import qualified Git.Config +import qualified Git.Branch header :: String header = "Usage: git-recover-repository" @@ -34,7 +35,7 @@ parseArgs = do enableDebugOutput :: IO () enableDebugOutput = do s <- setFormatter - <$> streamHandler stderr NOTICE + <$> streamHandler stderr DEBUG -- NOTICE <*> pure (simpleLogFormatter "$msg") updateGlobalLogger rootLoggerName (setLevel DEBUG . setHandlers [s]) @@ -66,8 +67,20 @@ main = do , show (length remotebranches) , "remote tracking branches that referred to missing objects" ] - localbranches <- Git.RecoverRepository.resetLocalBranches stillmissing goodcommits g - unless (null localbranches) $ do + (resetbranches, deletedbranches, _) <- Git.RecoverRepository.resetLocalBranches stillmissing goodcommits g + unless (null resetbranches) $ do putStrLn "Reset these local branches to old versions before the missing objects were committed:" - putStr $ unlines $ map show localbranches + putStr $ unlines $ map show resetbranches + unless (null deletedbranches) $ do + putStrLn "Deleted these local branches, which could not be recovered due to missing objects:" + putStr $ unlines $ map show deletedbranches + mcurr <- Git.Branch.currentUnsafe g + case mcurr of + Nothing -> return () + Just curr -> when (any (== curr) (resetbranches ++ deletedbranches)) $ do + putStrLn $ unwords + [ "You currently have" + , show curr + , "checked out. You may have staged changes in the index that can be committed to recover the lost state of this branch!" + ] else putStrLn "To force a recovery to a usable state, run this command again with the --force parameter." -- cgit v1.2.3