From db5d831d076527c4725bc57e6cb88c343ea670ba Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 11 May 2015 12:57:47 -0400 Subject: [PATCH] import: Refuse to import files that are within the work tree, as that does not make sense and could cause data loss. --- Command/Import.hs | 5 +++++ debian/changelog | 7 +++++++ ...ss_when_doing___96__git_annex_import_--force__96__.mdwn | 3 +++ 3 files changed, 15 insertions(+) diff --git a/Command/Import.hs b/Command/Import.hs index eb21faea23..fffa301ec9 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -9,6 +9,7 @@ module Command.Import where import Common.Annex import Command +import qualified Git import qualified Annex import qualified Command.Add import Utility.CopyFile @@ -62,6 +63,10 @@ getDuplicateMode = go . catMaybes <$> mapM getflag [minBound..maxBound] seek :: CommandSeek seek ps = do mode <- getDuplicateMode + repopath <- liftIO . absPath =<< fromRepo Git.repoPath + inrepops <- liftIO $ filter (dirContains repopath) <$> mapM absPath ps + unless (null inrepops) $ do + error $ "cannot import files from inside the working tree (use git annex add instead): " ++ unwords inrepops withPathContents (start mode) ps start :: DuplicateMode -> (FilePath, FilePath) -> CommandStart diff --git a/debian/changelog b/debian/changelog index cd7ade7b7f..58921d5a9b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +git-annex (5.20150508.2) UNRELEASED; urgency=medium + + * import: Refuse to import files that are within the work tree, as that + does not make sense and could cause data loss. + + -- Joey Hess Mon, 11 May 2015 12:45:06 -0400 + git-annex (5.20150508.1) unstable; urgency=medium * Now builds cleanly using ghc 7.10 (as well as ghc back to 7.6). diff --git a/doc/bugs/Data_loss_when_doing___96__git_annex_import_--force__96__.mdwn b/doc/bugs/Data_loss_when_doing___96__git_annex_import_--force__96__.mdwn index 8c61ba8d53..60e04fc146 100644 --- a/doc/bugs/Data_loss_when_doing___96__git_annex_import_--force__96__.mdwn +++ b/doc/bugs/Data_loss_when_doing___96__git_annex_import_--force__96__.mdwn @@ -57,3 +57,6 @@ drwx------ 55 jkt jkt 8.0K May 8 13:54 .. drwxr-xr-x 8 jkt jkt 119 May 8 13:55 .git """]] ...and the file is gone :(. + +> You should use `git annex add` in this case, not import. +> I've made import refuse to run in this case. [[done]] --[[Joey]]