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.
This commit is contained in:
Joey Hess 2012-05-31 19:47:18 -04:00
parent 3b09281b44
commit 3a10095d40
5 changed files with 61 additions and 1 deletions

39
Command/Import.hs Normal file
View file

@ -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

View file

@ -54,6 +54,7 @@ import qualified Command.Semitrust
import qualified Command.Dead
import qualified Command.Sync
import qualified Command.AddUrl
import qualified Command.Import
import qualified Command.Map
import qualified Command.Upgrade
import qualified Command.Version
@ -69,6 +70,7 @@ cmds = concat
, Command.Lock.def
, Command.Sync.def
, Command.AddUrl.def
, Command.Import.def
, Command.Init.def
, Command.Describe.def
, Command.InitRemote.def

10
Seek.hs
View file

@ -4,7 +4,7 @@
- the values a user passes to a command, and prepare actions operating
- on them.
-
- Copyright 2010-2011 Joey Hess <joey@kitenet.net>
- Copyright 2010-2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@ -41,6 +41,14 @@ withFilesNotInGit a params = do
g <- gitRepo
liftIO $ (\p -> LsFiles.notInRepo force p g) l
withPathContents :: ((FilePath, FilePath) -> CommandStart) -> CommandSeek
withPathContents a params = map a . concat <$> liftIO (mapM get params)
where
get p = ifM (isDirectory <$> getFileStatus p)
( map (\f -> (f, makeRelative p f)) <$> dirContentsRecursive p
, return [(p, takeFileName p)]
)
withWords :: ([String] -> CommandStart) -> CommandSeek
withWords a params = return [a params]

2
debian/changelog vendored
View file

@ -2,6 +2,8 @@ git-annex (3.20120523) UNRELEASED; urgency=low
* sync: Show a nicer message if a user tries to sync to a special remote.
* lock: Reset unlocked file to index, rather than to branch head.
* import: New subcommand, pulls files from a directory outside the annex
and adds them.
-- Joey Hess <joeyh@debian.org> Sun, 27 May 2012 20:55:29 -0400

View file

@ -160,6 +160,15 @@ subdirectories).
alternate locations from which the file can be downloaded. In this mode,
addurl can be used both to add new files, or to add urls to existing files.
* import [path ...]
Moves files from somewhere outside the git working copy, and adds them to
the annex. Individual files to import can be specified.
If a directory is specified, all files in it are imported, and any
subdirectory structure inside it is preserved.
git annex import /media/camera/DCIM/
# REPOSITORY SETUP COMMANDS
* init [description]