aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Assistant/Threads/SanityChecker.hs19
-rw-r--r--Git/Repair.hs24
2 files changed, 25 insertions, 18 deletions
diff --git a/Assistant/Threads/SanityChecker.hs b/Assistant/Threads/SanityChecker.hs
index 585a85cdf..b7dd45a21 100644
--- a/Assistant/Threads/SanityChecker.hs
+++ b/Assistant/Threads/SanityChecker.hs
@@ -40,13 +40,18 @@ sanityCheckerStartupThread startupdelay = namedThreadUnchecked "SanityCheckerSta
{- A corrupt index file can prevent the assistant from working at
- all, so detect and repair. -}
- unlessM (liftAnnex $ inRepo $ checkIndex S.empty) $ do
- debug ["corrupt index found at startup; removing"]
- liftAnnex $ inRepo nukeIndex
- {- Normally the startup scan avoids re-staging files,
- - but with the index deleted, everything needs to be
- - restaged. -}
- modifyDaemonStatus_ $ \s -> s { forceRestage = True }
+ ifM (liftAnnex $ inRepo $ checkIndex S.empty)
+ ( do
+ debug ["corrupt index file found at startup; removing and restaging"]
+ liftAnnex $ inRepo nukeIndex
+ {- Normally the startup scan avoids re-staging files,
+ - but with the index deleted, everything needs to be
+ - restaged. -}
+ modifyDaemonStatus_ $ \s -> s { forceRestage = True }
+ , whenM (liftAnnex $ inRepo missingIndex) $ do
+ debug ["no index file; restaging"]
+ modifyDaemonStatus_ $ \s -> s { forceRestage = True }
+ )
{- If there's a startup delay, it's done here. -}
liftIO $ maybe noop (threadDelaySeconds . Seconds . fromIntegral . durationSeconds) startupdelay
diff --git a/Git/Repair.hs b/Git/Repair.hs
index 85fcc6680..4265f8796 100644
--- a/Git/Repair.hs
+++ b/Git/Repair.hs
@@ -13,6 +13,7 @@ module Git.Repair (
resetLocalBranches,
removeTrackingBranches,
checkIndex,
+ missingIndex,
nukeIndex,
emptyGoodCommits,
) where
@@ -369,18 +370,19 @@ verifyTree missing treesha r
else cleanup
{- Checks that the index file only refers to objects that are not missing,
- - and is not itself corrupt or missing. -}
+ - and is not itself corrupt. Note that a missing index file is not
+ - considered a problem (repo may be new). -}
checkIndex :: MissingObjects -> Repo -> IO Bool
-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
- )
+checkIndex missing r = do
+ (bad, _good, cleanup) <- partitionIndex missing r
+ if null bad
+ then cleanup
+ else do
+ void cleanup
+ return False
+
+missingIndex :: Repo -> IO Bool
+missingIndex r = not <$> doesFileExist (localGitDir r </> "index")
partitionIndex :: MissingObjects -> Repo -> IO ([LsFiles.StagedDetails], [LsFiles.StagedDetails], IO Bool)
partitionIndex missing r = do