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-15 16:21:08 -04:00
|
|
|
import Logs.Location
|
2011-10-04 00:40:47 -04:00
|
|
|
import Annex.Content
|
2011-12-14 15:56:11 -04:00
|
|
|
import qualified Git.Command
|
2011-06-30 13:16:57 -04:00
|
|
|
import qualified Git.LsFiles as LsFiles
|
2010-11-02 19:04:24 -04:00
|
|
|
|
2011-10-29 15:19:05 -04:00
|
|
|
def :: [Command]
|
2012-12-29 14:28:19 -04:00
|
|
|
def = [notDirect $
|
2013-03-24 18:28:21 -04:00
|
|
|
command "unannex" paramPaths seek SectionUtility
|
|
|
|
"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
|
|
|
|
2011-12-31 04:11:39 -04:00
|
|
|
start :: FilePath -> (Key, Backend) -> CommandStart
|
2011-12-09 12:23:45 -04:00
|
|
|
start file (key, _) = stopUnless (inAnnex key) $ do
|
|
|
|
showStart "unannex" file
|
|
|
|
next $ perform file key
|
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-12-09 13:07:31 -04:00
|
|
|
-- git rm deletes empty directory without --cached
|
2013-03-03 13:39:07 -04:00
|
|
|
inRepo $ Git.Command.run [Params "rm --cached --quiet --", File file]
|
2011-12-09 13:07:31 -04: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.
|
2012-10-04 19:56:32 -04:00
|
|
|
(s, clean) <- inRepo $ LsFiles.staged [file]
|
|
|
|
when (not $ null s) $ do
|
2013-03-03 13:39:07 -04:00
|
|
|
inRepo $ Git.Command.run
|
|
|
|
[ Param "commit"
|
|
|
|
, Param "-q"
|
|
|
|
, Param "-m", Param "content removed from git annex"
|
|
|
|
, Param "--", File file
|
|
|
|
]
|
2012-10-04 19:56:32 -04:00
|
|
|
void $ liftIO clean
|
2010-11-08 19:26:37 -04:00
|
|
|
|
2012-03-14 17:43:34 -04:00
|
|
|
ifM (Annex.getState Annex.fast)
|
2013-02-06 14:02:18 -04:00
|
|
|
( goFast
|
|
|
|
, go
|
2012-03-14 17:43:34 -04:00
|
|
|
)
|
2011-12-09 13:07:31 -04:00
|
|
|
|
2010-11-02 19:04:24 -04:00
|
|
|
return True
|
2013-02-06 14:02:18 -04:00
|
|
|
where
|
|
|
|
goFast = do
|
|
|
|
-- fast mode: hard link to content in annex
|
2013-04-04 15:46:33 -04:00
|
|
|
src <- calcRepo $ gitAnnexLocation key
|
2013-02-06 14:02:18 -04:00
|
|
|
-- creating a hard link could fall; fall back to non fast mode
|
|
|
|
ifM (liftIO $ catchBoolIO $ createLink src file >> return True)
|
|
|
|
( thawContent file
|
|
|
|
, go
|
|
|
|
)
|
|
|
|
go = do
|
|
|
|
fromAnnex key file
|
|
|
|
logStatus key InfoMissing
|