add test cases for git/annexed conversions
authorJoey Hess <joeyh@joeyh.name>
Mon, 10 May 2021 18:19:24 +0000 (14:19 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 10 May 2021 18:29:57 +0000 (14:29 -0400)
Make sure that tip keeps working.

I tried to go futher and touch the file and make sure it stayed what it
was converted to, but struggled with some weird and not entirely
reproducable behavior, so kept the tests simple for now.

Test.hs
Test/Framework.hs

diff --git a/Test.hs b/Test.hs
index 6bb833c78f28418eeb1071c06089981b65edeb44..300ec157ffee1f1cc8ee6be0fdb453b544eb7c2c 100644 (file)
--- a/Test.hs
+++ b/Test.hs
@@ -340,6 +340,8 @@ unitTests note = testGroup ("Unit Tests " ++ note)
        , testCase "fsck (local untrusted)" test_fsck_localuntrusted
        , testCase "fsck (remote untrusted)" test_fsck_remoteuntrusted
        , testCase "fsck --from remote" test_fsck_fromremote
+       , testCase "conversion git to annexed" test_conversion_git_to_annexed
+       , testCase "conversion annexed to git" test_conversion_annexed_to_git
        , testCase "migrate" test_migrate
        , testCase "migrate (via gitattributes)" test_migrate_via_gitattributes
        , testCase "unused" test_unused
@@ -926,6 +928,28 @@ fsck_should_fail :: String -> Assertion
 fsck_should_fail m = git_annex_shouldfail "fsck" []
        ("fsck should not succeed with " ++ m)
 
+-- Make sure that the "converting git to annexed" recipe in
+-- doc/tips/largefiles.mdwn continues to work.
+test_conversion_git_to_annexed :: Assertion
+test_conversion_git_to_annexed = intmpclonerepo $ do
+       git "rm" ["--cached", ingitfile] "git rm --cached"
+       git_annex "add" ["--force-large", ingitfile] "add --force-large"
+       git "commit" ["-q", "-m", "commit", ingitfile] "git commit"
+       whenM (unlockedFiles <$> getTestMode) $
+               git_annex "unlock" [ingitfile] "unlock"
+       annexed_present ingitfile
+
+-- Make sure that the "converting annexed to git" recipe in
+-- doc/tips/largefiles.mdwn continues to work.
+test_conversion_annexed_to_git :: Assertion
+test_conversion_annexed_to_git = intmpclonerepo $ do   
+       git_annex "get" [annexedfile] "get"
+       git_annex "unlock" [annexedfile] "unlock"
+       git "rm" ["--cached", annexedfile] "git rm --cached"
+       git_annex "add" ["--force-small", annexedfile] "add --force-small"
+       git "commit" ["-q", "-m", "commit", annexedfile] "git commit"
+       unannexed_in_git annexedfile
+
 test_migrate :: Assertion
 test_migrate = test_migrate' False
 
index 22941e73632eafcb8d9907680b9ee1ca65778e55..81b15eb195893adaea1bbb97b97b7ba6da1a19a5 100644 (file)
@@ -415,6 +415,16 @@ annexed_notpresent_imported f = ifM (annexeval Config.crippledFileSystem)
 unannexed :: FilePath -> Assertion
 unannexed = runchecks [checkregularfile, checkcontent, checkwritable]
 
+-- Check that a file is unannexed, but also that what's recorded in git
+-- is not an annexed file.
+unannexed_in_git :: FilePath -> Assertion
+unannexed_in_git f = do
+       unannexed f
+       r <- annexeval $ Annex.WorkTree.lookupKey (toRawFilePath f)
+       case r of
+               Just _k -> assertFailure $ f ++ " is annexed in git"
+               Nothing -> return ()
+
 add_annex :: FilePath -> String -> Assertion
 add_annex f faildesc = ifM (unlockedFiles <$> getTestMode)
        ( git "add" [f] faildesc