2012-05-31 23:47:18 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Import where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Command
|
|
|
|
import qualified Annex
|
|
|
|
import qualified Command.Add
|
|
|
|
|
|
|
|
def :: [Command]
|
2012-12-29 18:45:19 +00:00
|
|
|
def = [notDirect $ notBareRepo $ command "import" paramPaths seek
|
2013-03-24 22:28:21 +00:00
|
|
|
SectionCommon "move and add files from outside git working copy"]
|
2012-05-31 23:47:18 +00:00
|
|
|
|
|
|
|
seek :: [CommandSeek]
|
|
|
|
seek = [withPathContents start]
|
|
|
|
|
|
|
|
start :: (FilePath, FilePath) -> CommandStart
|
2012-12-29 18:45:19 +00:00
|
|
|
start (srcfile, destfile) =
|
2012-05-31 23:47:18 +00:00
|
|
|
ifM (liftIO $ isRegularFile <$> getSymbolicLinkStatus srcfile)
|
|
|
|
( do
|
|
|
|
showStart "import" destfile
|
|
|
|
next $ perform srcfile destfile
|
|
|
|
, stop
|
|
|
|
)
|
|
|
|
|
|
|
|
perform :: FilePath -> FilePath -> CommandPerform
|
|
|
|
perform srcfile destfile = do
|
|
|
|
whenM (liftIO $ doesFileExist destfile) $
|
|
|
|
unlessM (Annex.getState Annex.force) $
|
|
|
|
error $ "not overwriting existing " ++ destfile ++
|
|
|
|
" (use --force to override)"
|
2012-12-13 04:45:27 +00:00
|
|
|
|
2012-05-31 23:47:18 +00:00
|
|
|
liftIO $ createDirectoryIfMissing True (parentDir destfile)
|
|
|
|
liftIO $ moveFile srcfile destfile
|
|
|
|
Command.Add.perform destfile
|