]> dgit.raspbian.org Git - git-annex.git/commitdiff
add: Fix reversion when adding an annex link that has been moved to another directory
authorJoey Hess <joeyh@joeyh.name>
Tue, 5 Jul 2022 20:22:41 +0000 (16:22 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 5 Jul 2022 20:22:41 +0000 (16:22 -0400)
Fixes commit f259be7f39d6c1746b6b809f15b9a227624a0cd8

Sponsored-by: Dartmouth College's Datalad project
CHANGELOG
Command/Add.hs
Test.hs
doc/bugs/regression__58___annex_add_of_moved_file_errors_out.mdwn

index 34050d0b673109c4b6900fad213890cb1f60df0e..5f9c5dcd61ce018a87a3edeb83645fd9b2fb6e47 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -6,6 +6,8 @@ git-annex (10.20220625) UNRELEASED; urgency=medium
     commands that actually need it.
   * Fix building with the Assistant build flag disabled but the Webapp
     build flag enabled.
+  * add: Fix reversion when adding an annex link that has been moved to
+    another directory. (Introduced in version 10.20220624)
 
  -- Joey Hess <id@joeyh.name>  Tue, 28 Jun 2022 14:49:17 -0400
 
index 13fc78d018b7bcd6d468689e1b940f85a8902bae..ffda19280538e32e536e3403d51ee144ad2b48c2 100644 (file)
@@ -210,7 +210,7 @@ start si file addunlockedmatcher =
                starting "add" (ActionItemTreeFile file) si $
                        addingExistingLink file key $
                                withOtherTmp $ \tmp -> do
-                                       let tmpf = tmp P.</> file
+                                       let tmpf = tmp P.</> P.takeFileName file
                                        liftIO $ moveFile file tmpf
                                        ifM (isSymbolicLink <$> liftIO (R.getSymbolicLinkStatus tmpf))
                                                ( do
diff --git a/Test.hs b/Test.hs
index 29897b27e008e0d561281bff59b87d29792760a2..79c6adcca6a64dd6272d7aa3a9dc31bf40048b2d 100644 (file)
--- a/Test.hs
+++ b/Test.hs
@@ -82,6 +82,7 @@ import qualified Utility.Tmp.Dir
 import qualified Utility.FileSystemEncoding
 import qualified Utility.Aeson
 import qualified Utility.CopyFile
+import qualified Utility.MoveFile
 import qualified Types.Remote
 #ifndef mingw32_HOST_OS
 import qualified Remote.Helper.Encryptable
@@ -261,6 +262,7 @@ repoTests :: String -> Int -> [TestTree]
 repoTests note numparts = map mk $ sep
        [ testCase "add dup" test_add_dup
        , testCase "add extras" test_add_extras
+       , testCase "add moved link" test_add_moved
        , testCase "readonly remote" test_readonly_remote
        , testCase "ignore deleted files" test_ignore_deleted_files
        , testCase "metadata" test_metadata
@@ -390,6 +392,17 @@ test_add_extras = intmpclonerepo $ do
        annexed_present wormannexedfile
        checkbackend wormannexedfile backendWORM
 
+test_add_moved :: Assertion
+test_add_moved = intmpclonerepo $ do
+       git_annex "get" [annexedfile] "get failed"
+       annexed_present annexedfile
+       createDirectory subdir
+       Utility.MoveFile.moveFile (toRawFilePath annexedfile) (toRawFilePath subfile)
+       git_annex "add" [subdir] "add of moved annexed file"
+  where
+       subdir = "subdir"
+       subfile = subdir </> "file"
+
 test_readonly_remote :: Assertion
 test_readonly_remote =
 #ifndef mingw32_HOST_OS
index 895460f87ca939c31d8fc01e106826b3320ac4ae..10a7e25c36a001feacf70128fe46ec3c1630e0dc 100644 (file)
@@ -44,3 +44,5 @@ As this is such a basic operation, I am still wondering how come it is not caugh
 
 [[!meta author=yoh]]
 [[!tag projects/datalad]]
+
+> [[fixed|done]], with a test case added for this edge case. --[[Joey]]