2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Unannex where
|
|
|
|
|
|
|
|
import Control.Monad.State (liftIO)
|
|
|
|
import System.Directory
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Annex
|
|
|
|
import Utility
|
|
|
|
import qualified Backend
|
|
|
|
import LocationLog
|
|
|
|
import Types
|
2011-01-16 20:05:05 +00:00
|
|
|
import Content
|
2010-11-02 23:04:24 +00:00
|
|
|
import qualified GitRepo as Git
|
2010-11-08 19:15:21 +00:00
|
|
|
import Messages
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 19:06:26 +00:00
|
|
|
command :: [Command]
|
|
|
|
command = [Command "unannex" paramPath seek "undo accidential add command"]
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2010-11-11 22:54:52 +00:00
|
|
|
seek = [withFilesInGit start]
|
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
{- The unannex subcommand undoes an add. -}
|
2010-12-30 18:19:16 +00:00
|
|
|
start :: CommandStartString
|
2010-11-02 23:04:24 +00:00
|
|
|
start file = isAnnexed file $ \(key, backend) -> do
|
2011-01-08 19:14:41 +00:00
|
|
|
ishere <- inAnnex key
|
|
|
|
if ishere
|
|
|
|
then do
|
|
|
|
showStart "unannex" file
|
|
|
|
return $ Just $ perform file key backend
|
|
|
|
else return Nothing
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-01-26 01:02:34 +00:00
|
|
|
perform :: FilePath -> Key -> Backend Annex -> CommandPerform
|
2010-11-02 23:04:24 +00:00
|
|
|
perform file key backend = do
|
|
|
|
-- force backend to always remove
|
2010-11-28 19:28:20 +00:00
|
|
|
ok <- Backend.removeKey backend key (Just 0)
|
2010-11-22 21:51:55 +00:00
|
|
|
if ok
|
2010-11-02 23:04:24 +00:00
|
|
|
then return $ Just $ cleanup file key
|
|
|
|
else return Nothing
|
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
cleanup :: FilePath -> Key -> CommandCleanup
|
2010-11-02 23:04:24 +00:00
|
|
|
cleanup file key = do
|
|
|
|
g <- Annex.gitRepo
|
2010-11-08 23:26:37 +00:00
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
liftIO $ removeFile file
|
2010-11-10 18:15:21 +00:00
|
|
|
liftIO $ Git.run g ["rm", "--quiet", "--", file]
|
2010-11-02 23:04:24 +00:00
|
|
|
-- git rm deletes empty directories; put them back
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
2010-11-08 23:26:37 +00:00
|
|
|
|
|
|
|
fromAnnex key file
|
|
|
|
logStatus key ValueMissing
|
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|