diff options
author | Joey Hess <joey@kitenet.net> | 2013-11-20 13:01:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-11-20 13:13:24 -0400 |
commit | 229761fc4397ed3e8b137e65657a2583066d2764 (patch) | |
tree | 23a86559b66c670dbb7f38e4bf0eefc15458be96 /Git | |
parent | 3ed32d99829ca44abfe43c953800d8d249909997 (diff) | |
download | git-repair-229761fc4397ed3e8b137e65657a2583066d2764.tar.gz |
Write a dummy .git/HEAD if the file is missing, as git otherwise will not treat the repository as a git repo.
Diffstat (limited to 'Git')
-rw-r--r-- | Git/Repair.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Git/Repair.hs b/Git/Repair.hs index 3e731aa..c5ec40b 100644 --- a/Git/Repair.hs +++ b/Git/Repair.hs @@ -36,6 +36,7 @@ import qualified Git.UpdateIndex as UpdateIndex import qualified Git.Branch as Branch import Utility.Tmp import Utility.Rsync +import Utility.FileMode import qualified Data.Set as S import qualified Data.ByteString.Lazy as L @@ -444,9 +445,27 @@ displayList items header | numitems > 10 = take 10 items ++ ["(and " ++ show (numitems - 10) ++ " more)"] | otherwise = items +{- Fix problems that would prevent repair from working at all + - + - A missing or corrupt .git/HEAD makes git not treat the repository as a + - git repo. If there is a git repo in a parent directory, it may move up + - the tree and use that one instead. So, cannot use `git show-ref HEAD` to + - test it. + -} +preRepair :: Repo -> IO () +preRepair g = do + void $ tryIO $ allowRead headfile + unlessM (validhead <$> catchDefaultIO "" (readFile headfile)) $ do + nukeFile headfile + writeFile headfile "ref: refs/heads/master" + where + headfile = localGitDir g </> "HEAD" + validhead s = "ref: " `isPrefixOf` s || isJust (extractSha s) + {- Put it all together. -} runRepair :: Bool -> Repo -> IO (Bool, MissingObjects, [Branch]) runRepair forced g = do + preRepair g putStrLn "Running git fsck ..." fsckresult <- findBroken False g if foundBroken fsckresult |