git-annex/Command/Uninit.hs

73 lines
2.2 KiB
Haskell
Raw Normal View History

2010-12-03 04:33:41 +00:00
{- git-annex command
-
- Copyright 2010 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Uninit where
2011-10-05 20:02:51 +00:00
import Common.Annex
2010-12-03 04:33:41 +00:00
import Command
import qualified Git
2011-12-14 19:56:11 +00:00
import qualified Git.Command
2010-12-03 04:33:41 +00:00
import qualified Annex
import qualified Command.Unannex
import Init
2011-10-04 04:40:47 +00:00
import qualified Annex.Branch
import Annex.Content
2010-12-03 04:33:41 +00:00
def :: [Command]
def = [addCheck check $ command "uninit" paramPaths seek
2012-12-13 04:45:27 +00:00
"de-initialize git-annex and clean out repository"]
check :: Annex ()
check = do
b <- current_branch
when (b == Annex.Branch.name) $ error $
"cannot uninit when the " ++ show b ++ " branch is checked out"
top <- fromRepo Git.repoPath
cwd <- liftIO getCurrentDirectory
2012-06-12 15:32:06 +00:00
whenM ((/=) <$> liftIO (absPath top) <*> liftIO (absPath cwd)) $
error "can only run uninit from the top of the git repository"
2012-11-12 05:05:04 +00:00
where
current_branch = Git.Ref . Prelude.head . lines <$> revhead
revhead = inRepo $ Git.Command.pipeReadStrict
[Params "rev-parse --abbrev-ref HEAD"]
seek :: [CommandSeek]
2012-11-25 19:52:35 +00:00
seek =
[ withFilesNotInGit $ whenAnnexed startCheckIncomplete
, withFilesInGit $ whenAnnexed startUnannex
, withNothing start
]
{- git annex symlinks that are not checked into git could be left by an
- interrupted add. -}
startCheckIncomplete :: FilePath -> (Key, Backend) -> CommandStart
startCheckIncomplete file _ = error $ unlines
[ file ++ " points to annexed content, but is not checked into git."
, "Perhaps this was left behind by an interrupted git annex add?"
, "Not continuing with uninit; either delete or git annex add the file and retry."
]
2011-12-31 08:11:39 +00:00
startUnannex :: FilePath -> (Key, Backend) -> CommandStart
startUnannex file info = do
-- Force fast mode before running unannex. This way, if multiple
-- files link to a key, it will be left in the annex and hardlinked
-- to by each.
Annex.changeState $ \s -> s { Annex.fast = True }
Command.Unannex.start file info
2010-12-03 04:33:41 +00:00
start :: CommandStart
start = next $ next $ do
2011-11-11 05:52:58 +00:00
annexdir <- fromRepo gitAnnexDir
uninitialize
mapM_ removeAnnex =<< getKeysPresent
liftIO $ removeDirectoryRecursive annexdir
-- avoid normal shutdown
saveState False
2011-12-14 19:56:11 +00:00
inRepo $ Git.Command.run "branch"
[Param "-D", Param $ show Annex.Branch.name]
2011-11-11 05:52:58 +00:00
liftIO exitSuccess