summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2013-11-21 20:23:07 -0400
committerJoey Hess <joey@kitenet.net>2013-11-21 20:23:07 -0400
commit3cab695e89afa40bba04e5b0e2de45bda1501e6c (patch)
treec624a512c0ea9097cedc0a1e94bd862e19544c01
parent2627ebbe56c962407fa0193d77f4a2a61596d87d (diff)
downloadgit-repair-3cab695e89afa40bba04e5b0e2de45bda1501e6c.tar.gz
make sure index file is writable in pre-repair
-rw-r--r--Git/Repair.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/Git/Repair.hs b/Git/Repair.hs
index 2fe9f38..dafdd3f 100644
--- a/Git/Repair.hs
+++ b/Git/Repair.hs
@@ -15,7 +15,6 @@ module Git.Repair (
removeTrackingBranches,
checkIndex,
missingIndex,
- nukeIndex,
emptyGoodCommits,
) where
@@ -368,7 +367,7 @@ rewriteIndex missing r
| otherwise = do
(bad, good, cleanup) <- partitionIndex missing r
unless (null bad) $ do
- nukeIndex r
+ nukeFile (indexFile r)
UpdateIndex.streamUpdateIndex r
=<< (catMaybes <$> mapM reinject good)
void cleanup
@@ -380,8 +379,8 @@ rewriteIndex missing r
UpdateIndex.stageFile sha blobtype file r
reinject _ = return Nothing
-nukeIndex :: Repo -> IO ()
-nukeIndex r = nukeFile (localGitDir r </> "index")
+indexFile :: Repo -> FilePath
+indexFile r = localGitDir r </> "index"
newtype GoodCommits = GoodCommits (S.Set Sha)
@@ -423,6 +422,9 @@ preRepair g = do
nukeFile headfile
writeFile headfile "ref: refs/heads/master"
explodePackedRefsFile g
+ unless (repoIsLocalBare g) $ do
+ let f = indexFile g
+ void $ tryIO $ allowWrite f
where
headfile = localGitDir g </> "HEAD"
validhead s = "ref: refs/" `isPrefixOf` s || isJust (extractSha s)
@@ -517,7 +519,7 @@ runRepair' fsckresult forced referencerepo g = do
return (True, stillmissing, modifiedbranches)
corruptedindex = do
- nukeIndex g
+ nukeFile (indexFile g)
-- The corrupted index can prevent fsck from finding other
-- problems, so re-run repair.
fsckresult' <- findBroken False g