summaryrefslogtreecommitdiff
path: root/git-recover-repository.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-10-23 12:21:59 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-10-23 12:21:59 -0400
commitfb2ccfd60ff09c1b1d03838d42eba3c65fd7fb27 (patch)
tree6311388390b6bd61c98bd770460a0275584aa500 /git-recover-repository.hs
parent3aca9448cf014262e4ffd42c2ebf729d4f0a2282 (diff)
add repair command
Diffstat (limited to 'git-recover-repository.hs')
-rw-r--r--git-recover-repository.hs75
1 files changed, 4 insertions, 71 deletions
diff --git a/git-recover-repository.hs b/git-recover-repository.hs
index d2249a433..9f1ffb423 100644
--- a/git-recover-repository.hs
+++ b/git-recover-repository.hs
@@ -6,10 +6,6 @@
-}
import System.Environment
-import System.Log.Logger
-import System.Log.Formatter
-import System.Log.Handler (setFormatter)
-import System.Log.Handler.Simple
import qualified Data.Set as S
import Common
@@ -34,75 +30,12 @@ parseArgs = do
parse "--force" = True
parse _ = usage
-enableDebugOutput :: IO ()
-enableDebugOutput = do
- s <- setFormatter
- <$> streamHandler stderr NOTICE
- <*> pure (simpleLogFormatter "$msg")
- updateGlobalLogger rootLoggerName (setLevel DEBUG . setHandlers [s])
-
main :: IO ()
main = do
- enableDebugOutput
forced <- parseArgs
g <- Git.Config.read =<< Git.CurrentRepo.get
- putStrLn "Running git fsck ..."
- fsckresult <- Git.Fsck.findBroken False g
- missing <- Git.RecoverRepository.cleanCorruptObjects fsckresult g
- stillmissing <- Git.RecoverRepository.retrieveMissingObjects missing g
- if S.null stillmissing
- then putStr $ unlines
- [ "Successfully recovered repository!"
- , "You should run \"git fsck\" to make sure, but it looks like"
- , "everything was recovered ok."
- ]
- else do
- putStrLn $ unwords
- [ show (S.size stillmissing)
- , "missing objects could not be recovered!"
- ]
- if forced
- then do
- (remotebranches, goodcommits) <- Git.RecoverRepository.removeTrackingBranches stillmissing Git.RecoverRepository.emptyGoodCommits g
- unless (null remotebranches) $
- putStrLn $ unwords
- [ "removed"
- , show (length remotebranches)
- , "remote tracking branches that referred to missing objects"
- ]
- (resetbranches, deletedbranches, _) <- Git.RecoverRepository.resetLocalBranches stillmissing goodcommits g
- printList (map show resetbranches)
- "Reset these local branches to old versions before the missing objects were committed:"
- printList (map show deletedbranches)
- "Deleted these local branches, which could not be recovered due to missing objects:"
- deindexedfiles <- Git.RecoverRepository.rewriteIndex stillmissing g
- printList deindexedfiles
- "Removed these missing files from the index. You should look at what files are present in your working tree and git add them back to the index when appropriate."
- unless (Git.repoIsLocalBare g) $ do
- 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 if Git.repoIsLocalBare g
- then do
- putStrLn "If you have a clone of this bare repository, you should add it as a remote of this repository, and re-run git-recover-repository."
- putStrLn "If there are no clones of this repository, you can instead run git-recover-repository with the --force parameter to force recovery to a possibly usable state."
- else putStrLn "To force a recovery to a usable state, run this command again with the --force parameter."
-
-printList :: [String] -> String -> IO ()
-printList items header
- | null items = return ()
- | otherwise = do
- putStrLn header
- putStr $ unlines $ map (\i -> "\t" ++ i) truncateditems
- where
- numitems = length items
- truncateditems
- | numitems > 10 = take 10 items ++ ["(and " ++ show (numitems - 10) ++ " more)"]
- | otherwise = items
+ ifM (Git.RecoverRepository.runRecovery forced g)
+ ( exitSuccess
+ , exitFailure
+ )