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
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2010-11-02 23:04:24 +00:00
|
|
|
import Command
|
|
|
|
import qualified Annex
|
2011-09-23 22:13:24 +00:00
|
|
|
import Utility.FileMode
|
2011-10-15 20:21:08 +00:00
|
|
|
import Logs.Location
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Content
|
2011-12-14 19:56:11 +00:00
|
|
|
import qualified Git.Command
|
2011-06-30 17:16:57 +00:00
|
|
|
import qualified Git.LsFiles as LsFiles
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-10-29 19:19:05 +00:00
|
|
|
def :: [Command]
|
|
|
|
def = [command "unannex" paramPaths seek "undo accidential add command"]
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
seek :: [CommandSeek]
|
2011-11-11 03:35:08 +00:00
|
|
|
seek = [withFilesInGit $ whenAnnexed start]
|
2010-11-11 22:54:52 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
start :: FilePath -> (Key, Backend) -> CommandStart
|
2011-12-09 16:23:45 +00:00
|
|
|
start file (key, _) = stopUnless (inAnnex key) $ do
|
|
|
|
showStart "unannex" file
|
|
|
|
next $ perform file key
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2011-07-05 22:31:46 +00:00
|
|
|
perform :: FilePath -> Key -> CommandPerform
|
2011-10-27 23:10:10 +00:00
|
|
|
perform file key = next $ cleanup file key
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-30 18:19:16 +00:00
|
|
|
cleanup :: FilePath -> Key -> CommandCleanup
|
2010-11-02 23:04:24 +00:00
|
|
|
cleanup file key = do
|
|
|
|
liftIO $ removeFile file
|
2011-12-09 17:07:31 +00:00
|
|
|
-- git rm deletes empty directory without --cached
|
2011-12-14 19:56:11 +00:00
|
|
|
inRepo $ Git.Command.run "rm" [Params "--cached --quiet --", File file]
|
2011-12-09 17:07:31 +00:00
|
|
|
|
|
|
|
-- If the file was already committed, it is now staged for removal.
|
|
|
|
-- Commit that removal now, to avoid later confusing the
|
|
|
|
-- pre-commit hook if this file is later added back to
|
|
|
|
-- git as a normal, non-annexed file.
|
|
|
|
whenM (not . null <$> inRepo (LsFiles.staged [file])) $ do
|
2011-12-22 18:50:20 +00:00
|
|
|
showOutput
|
2011-12-14 19:56:11 +00:00
|
|
|
inRepo $ Git.Command.run "commit" [
|
2011-12-22 18:50:20 +00:00
|
|
|
Param "-q",
|
|
|
|
Params "-m", Param "content removed from git annex",
|
2011-12-09 17:07:31 +00:00
|
|
|
Param "--", File file]
|
2010-11-08 23:26:37 +00:00
|
|
|
|
2011-07-04 20:06:28 +00:00
|
|
|
fast <- Annex.getState Annex.fast
|
|
|
|
if fast
|
2011-11-08 19:34:10 +00:00
|
|
|
then do
|
2011-07-04 20:06:28 +00:00
|
|
|
-- fast mode: hard link to content in annex
|
2011-11-29 02:43:51 +00:00
|
|
|
src <- inRepo $ gitAnnexLocation key
|
2011-11-08 19:34:10 +00:00
|
|
|
liftIO $ do
|
|
|
|
createLink src file
|
|
|
|
allowWrite file
|
2011-07-04 20:06:28 +00:00
|
|
|
else do
|
|
|
|
fromAnnex key file
|
|
|
|
logStatus key InfoMissing
|
2011-12-09 17:07:31 +00:00
|
|
|
|
2010-11-02 23:04:24 +00:00
|
|
|
return True
|