repair: Handle case where index file is corrupt, but all objects are ok.

This commit is contained in:
Joey Hess 2013-11-13 13:41:02 -04:00
parent 20167fe945
commit 5e7e0c7dc0
2 changed files with 23 additions and 4 deletions

View file

@ -12,7 +12,6 @@ module Git.Repair (
retrieveMissingObjects,
resetLocalBranches,
removeTrackingBranches,
rewriteIndex,
checkIndex,
emptyGoodCommits,
) where
@ -368,7 +367,8 @@ verifyTree missing treesha r
-- as long as ls-tree succeeded, we're good
else cleanup
{- Checks that the index file only refers to objects that are not missing. -}
{- Checks that the index file only refers to objects that are not missing,
- and is not itself corrupt. -}
checkIndex :: MissingObjects -> Repo -> IO Bool
checkIndex missing r = do
(bad, _good, cleanup) <- partitionIndex missing r
@ -448,7 +448,16 @@ runRepairOf fsckresult forced referencerepo g = do
missing <- cleanCorruptObjects fsckresult g
stillmissing <- retrieveMissingObjects missing referencerepo g
if S.null stillmissing
then successfulfinish stillmissing []
then if repoIsLocalBare g
then successfulfinish stillmissing []
else ifM (checkIndex stillmissing g)
( successfulfinish stillmissing []
, do
putStrLn "No missing objects found, but the index file is corrupt!"
if forced
then corruptedindex
else needforce stillmissing
)
else do
putStrLn $ unwords
[ show (S.size stillmissing)
@ -491,6 +500,12 @@ runRepairOf fsckresult forced referencerepo g = do
putStrLn "Successfully recovered repository!"
putStrLn "Please carefully check that the changes mentioned above are ok.."
return (True, stillmissing, modifiedbranches)
corruptedindex = do
nukeFile (localGitDir g </> "index")
putStrLn "Removed the corrupted index file. You should look at what files are present in your working tree and git add them back to the index when appropriate."
return (True, S.empty, [])
successfulfinish stillmissing modifiedbranches = do
mapM_ putStrLn
[ "Successfully recovered repository!"
@ -503,5 +518,8 @@ runRepairOf fsckresult forced referencerepo g = do
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."
return (False, stillmissing, [])
else needforce stillmissing
needforce stillmissing = do
putStrLn "To force a recovery to a usable state, run this command again with the --force parameter."
return (False, stillmissing, [])

1
debian/changelog vendored
View file

@ -26,6 +26,7 @@ git-annex (5.20131102) UNRELEASED; urgency=low
when running describe or other commands with a remote that has no uuid.
* Work around Android linker problem that had prevented git-annex from
running on Android 4.3 and 4.4.
* repair: Handle case where index file is corrupt, but all objects are ok.
-- Joey Hess <joeyh@debian.org> Wed, 06 Nov 2013 16:14:14 -0400