aboutsummaryrefslogtreecommitdiff
path: root/Git/Repair.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-11-13 14:27:17 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-11-13 14:27:17 -0400
commit220d54ffbd0d3d3bba8662d1964c02fe1a44cb38 (patch)
treeb89a849426018b29239de3d94fdc9db19ca5295f /Git/Repair.hs
parent80742af4abedd516c458ec337495383e41d6f60c (diff)
assistant: Notice on startup when the index file is corrupt, and auto-repair.
Diffstat (limited to 'Git/Repair.hs')
-rw-r--r--Git/Repair.hs27
1 files changed, 17 insertions, 10 deletions
diff --git a/Git/Repair.hs b/Git/Repair.hs
index dbb43c06f..85fcc6680 100644
--- a/Git/Repair.hs
+++ b/Git/Repair.hs
@@ -13,6 +13,7 @@ module Git.Repair (
resetLocalBranches,
removeTrackingBranches,
checkIndex,
+ nukeIndex,
emptyGoodCommits,
) where
@@ -368,15 +369,18 @@ verifyTree missing treesha r
else cleanup
{- Checks that the index file only refers to objects that are not missing,
- - and is not itself corrupt. -}
+ - and is not itself corrupt or missing. -}
checkIndex :: MissingObjects -> Repo -> IO Bool
-checkIndex missing r = do
- (bad, _good, cleanup) <- partitionIndex missing r
- if null bad
- then cleanup
- else do
- void cleanup
- return False
+checkIndex missing r = ifM (doesFileExist (localGitDir r </> "index"))
+ ( do
+ (bad, _good, cleanup) <- partitionIndex missing r
+ if null bad
+ then cleanup
+ else do
+ void cleanup
+ return False
+ , return False
+ )
partitionIndex :: MissingObjects -> Repo -> IO ([LsFiles.StagedDetails], [LsFiles.StagedDetails], IO Bool)
partitionIndex missing r = do
@@ -396,7 +400,7 @@ rewriteIndex missing r
| otherwise = do
(bad, good, cleanup) <- partitionIndex missing r
unless (null bad) $ do
- nukeFile (localGitDir r </> "index")
+ nukeIndex r
UpdateIndex.streamUpdateIndex r
=<< (catMaybes <$> mapM reinject good)
void cleanup
@@ -408,6 +412,9 @@ rewriteIndex missing r
UpdateIndex.stageFile sha blobtype file r
reinject _ = return Nothing
+nukeIndex :: Repo -> IO ()
+nukeIndex r = nukeFile (localGitDir r </> "index")
+
newtype GoodCommits = GoodCommits (S.Set Sha)
emptyGoodCommits :: GoodCommits
@@ -502,7 +509,7 @@ runRepairOf fsckresult forced referencerepo g = do
return (True, stillmissing, modifiedbranches)
corruptedindex = do
- nukeFile (localGitDir g </> "index")
+ nukeIndex g
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, [])