aboutsummaryrefslogtreecommitdiff
path: root/Command/Import.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-05-31 19:47:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-05-31 19:47:18 -0400
commit3a10095d40cf9a9e0380b6b10e1ebe304f1537c0 (patch)
treea4dd1413473cddc7e7d5aff9ce1442b35347ed4e /Command/Import.hs
parent3b09281b442e794213f2e296e42e2d74fddec733 (diff)
import: New subcommand, pulls files from a directory outside the annex and adds them
Use case for this was developed somewhere on the Transiberian Railroad.
Diffstat (limited to 'Command/Import.hs')
-rw-r--r--Command/Import.hs39
1 files changed, 39 insertions, 0 deletions
diff --git a/Command/Import.hs b/Command/Import.hs
new file mode 100644
index 000000000..e27a421f2
--- /dev/null
+++ b/Command/Import.hs
@@ -0,0 +1,39 @@
+{- 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]
+def = [command "import" paramPaths seek "move and add files from outside git working copy"]
+
+seek :: [CommandSeek]
+seek = [withPathContents start]
+
+start :: (FilePath, FilePath) -> CommandStart
+start (srcfile, destfile) = notBareRepo $
+ 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)"
+
+ liftIO $ createDirectoryIfMissing True (parentDir destfile)
+ liftIO $ moveFile srcfile destfile
+ Command.Add.perform destfile