2010-11-02 19:04:24 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Unannex where
|
|
|
|
|
2011-10-05 16:02:51 -04:00
|
|
|
import Common.Annex
|
2010-11-02 19:04:24 -04:00
|
|
|
import Command
|
|
|
|
import qualified Annex
|
2011-10-04 00:40:47 -04:00
|
|
|
import qualified Annex.Queue
|
2011-09-23 18:13:24 -04:00
|
|
|
import Utility.FileMode
|
2011-10-15 16:21:08 -04:00
|
|
|
import Logs.Location
|
2011-10-04 00:40:47 -04:00
|
|
|
import Annex.Content
|
2011-06-30 13:16:57 -04:00
|
|
|
import qualified Git
|
|
|
|
import qualified Git.LsFiles as LsFiles
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2011-10-29 15:19:05 -04:00
|
|
|
def :: [Command]
|
|
|
|
def = [command "unannex" paramPaths seek "undo accidential add command"]
|
2010-12-30 15:06:26 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
seek :: [CommandSeek]
|
2011-11-10 23:35:08 -04:00
|
|
|
seek = [withFilesInGit $ whenAnnexed start]
|
2010-11-11 18:54:52 -04:00
|
|
|
|
2010-11-02 19:04:24 -04:00
|
|
|
{- The unannex subcommand undoes an add. -}
|
2011-11-10 23:35:08 -04:00
|
|
|
start :: FilePath -> (Key, Backend Annex) -> CommandStart
|
|
|
|
start file (key, _) = do
|
2011-01-08 15:14:41 -04:00
|
|
|
ishere <- inAnnex key
|
|
|
|
if ishere
|
|
|
|
then do
|
2011-02-09 11:02:21 -04:00
|
|
|
force <- Annex.getState Annex.force
|
|
|
|
unless force $ do
|
2011-11-08 15:34:10 -04:00
|
|
|
top <- fromRepo Git.workTree
|
|
|
|
staged <- inRepo $ LsFiles.staged [top]
|
2011-02-09 11:02:21 -04:00
|
|
|
unless (null staged) $
|
|
|
|
error "This command cannot be run when there are already files staged for commit."
|
|
|
|
Annex.changeState $ \s -> s { Annex.force = True }
|
2011-02-01 21:58:47 -04:00
|
|
|
|
2011-01-08 15:14:41 -04:00
|
|
|
showStart "unannex" file
|
2011-07-05 18:31:46 -04:00
|
|
|
next $ perform file key
|
2011-05-15 02:02:46 -04:00
|
|
|
else stop
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2011-07-05 18:31:46 -04:00
|
|
|
perform :: FilePath -> Key -> CommandPerform
|
2011-10-27 19:10:10 -04:00
|
|
|
perform file key = next $ cleanup file key
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2010-12-30 14:19:16 -04:00
|
|
|
cleanup :: FilePath -> Key -> CommandCleanup
|
2010-11-02 19:04:24 -04:00
|
|
|
cleanup file key = do
|
|
|
|
liftIO $ removeFile file
|
2011-11-08 15:34:10 -04:00
|
|
|
inRepo $ Git.run "rm" [Params "--quiet --", File file]
|
2010-11-02 19:04:24 -04:00
|
|
|
-- git rm deletes empty directories; put them back
|
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
2010-11-08 19:26:37 -04:00
|
|
|
|
2011-07-04 16:06:28 -04:00
|
|
|
fast <- Annex.getState Annex.fast
|
|
|
|
if fast
|
2011-11-08 15:34:10 -04:00
|
|
|
then do
|
2011-07-04 16:06:28 -04:00
|
|
|
-- fast mode: hard link to content in annex
|
2011-11-08 15:34:10 -04:00
|
|
|
src <- fromRepo $ gitAnnexLocation key
|
|
|
|
liftIO $ do
|
|
|
|
createLink src file
|
|
|
|
allowWrite file
|
2011-07-04 16:06:28 -04:00
|
|
|
else do
|
|
|
|
fromAnnex key file
|
|
|
|
logStatus key InfoMissing
|
2011-02-01 21:26:19 -04:00
|
|
|
|
|
|
|
-- Commit staged changes at end to avoid confusing the
|
|
|
|
-- pre-commit hook if this file is later added back to
|
|
|
|
-- git as a normal, non-annexed file.
|
2011-10-04 00:40:47 -04:00
|
|
|
Annex.Queue.add "commit" [Param "-m", Param "content removed from git annex"] []
|
2011-02-01 21:26:19 -04:00
|
|
|
|
2010-11-02 19:04:24 -04:00
|
|
|
return True
|