git-annex/Command/Unannex.hs

63 lines
1.6 KiB
Haskell
Raw Normal View History

{- 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
import Command
import qualified Annex
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-12-14 15:56:11 -04:00
import qualified Git.Command
import qualified Git.LsFiles as LsFiles
def :: [Command]
def = [command "unannex" paramPaths seek "undo accidential add command"]
seek :: [CommandSeek]
seek = [withFilesInGit $ whenAnnexed start]
2010-11-11 18:54:52 -04:00
start :: FilePath -> (Key, Backend Annex) -> CommandStart
start file (key, _) = stopUnless (inAnnex key) $ do
showStart "unannex" file
next $ perform file key
perform :: FilePath -> Key -> CommandPerform
2011-10-27 19:10:10 -04:00
perform file key = next $ cleanup file key
cleanup :: FilePath -> Key -> CommandCleanup
cleanup file key = do
liftIO $ removeFile file
-- git rm deletes empty directory without --cached
2011-12-14 15:56:11 -04:00
inRepo $ Git.Command.run "rm" [Params "--cached --quiet --", File file]
-- 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 14:50:20 -04:00
showOutput
2011-12-14 15:56:11 -04:00
inRepo $ Git.Command.run "commit" [
2011-12-22 14:50:20 -04:00
Param "-q",
Params "-m", Param "content removed from git annex",
Param "--", File file]
fast <- Annex.getState Annex.fast
if fast
then do
-- fast mode: hard link to content in annex
src <- inRepo $ gitAnnexLocation key
liftIO $ do
createLink src file
allowWrite file
else do
fromAnnex key file
logStatus key InfoMissing
return True