import: Don't stop entire import when one file fails due to being gitignored or conflicting with something in the work tree.

This commit is contained in:
Joey Hess 2015-04-29 13:56:41 -04:00
parent 548037223c
commit d8ad1d5503
2 changed files with 25 additions and 15 deletions

View file

@ -79,24 +79,32 @@ start mode (srcfile, destfile) =
liftIO $ removeFile srcfile liftIO $ removeFile srcfile
next $ return True next $ return True
importfile = do importfile = do
handleexisting =<< liftIO (catchMaybeIO $ getSymbolicLinkStatus destfile)
ignored <- not <$> Annex.getState Annex.force <&&> checkIgnored destfile ignored <- not <$> Annex.getState Annex.force <&&> checkIgnored destfile
if ignored if ignored
then error $ "not importing " ++ destfile ++ " which is .gitignored (use --force to override)" then do
warning $ "not importing " ++ destfile ++ " which is .gitignored (use --force to override)"
stop
else do else do
liftIO $ createDirectoryIfMissing True (parentDir destfile) existing <- liftIO (catchMaybeIO $ getSymbolicLinkStatus destfile)
liftIO $ if mode == Duplicate || mode == SkipDuplicates case existing of
then void $ copyFileExternal CopyAllMetaData srcfile destfile Nothing -> importfilechecked
else moveFile srcfile destfile (Just s)
Command.Add.perform destfile | isDirectory s -> notoverwriting "(is a directory)"
handleexisting Nothing = noop | otherwise -> ifM (Annex.getState Annex.force)
handleexisting (Just s) ( do
| isDirectory s = notoverwriting "(is a directory)" liftIO $ nukeFile destfile
| otherwise = ifM (Annex.getState Annex.force) importfilechecked
( liftIO $ nukeFile destfile , notoverwriting "(use --force to override, or a duplication option such as --deduplicate to clean up)"
, notoverwriting "(use --force to override, or a duplication option such as --deduplicate to clean up)" )
) importfilechecked = do
notoverwriting why = error $ "not overwriting existing " ++ destfile ++ " " ++ why liftIO $ createDirectoryIfMissing True (parentDir destfile)
liftIO $ if mode == Duplicate || mode == SkipDuplicates
then void $ copyFileExternal CopyAllMetaData srcfile destfile
else moveFile srcfile destfile
Command.Add.perform destfile
notoverwriting why = do
warning $ "not overwriting existing " ++ destfile ++ " " ++ why
stop
checkdup dupa notdupa = do checkdup dupa notdupa = do
backend <- chooseBackend destfile backend <- chooseBackend destfile
let ks = KeySource srcfile srcfile Nothing let ks = KeySource srcfile srcfile Nothing

2
debian/changelog vendored
View file

@ -13,6 +13,8 @@ git-annex (5.20150421) UNRELEASED; urgency=medium
lower case automatically. lower case automatically.
* import: Check for gitignored files before moving them into the tree. * import: Check for gitignored files before moving them into the tree.
(Needs git 1.8.4 or newer.) (Needs git 1.8.4 or newer.)
* import: Don't stop entire import when one file fails due to being
gitignored or conflicting with something in the work tree.
-- Joey Hess <id@joeyh.name> Tue, 21 Apr 2015 15:54:10 -0400 -- Joey Hess <id@joeyh.name> Tue, 21 Apr 2015 15:54:10 -0400