add test case for readonly remote
authorJoey Hess <joeyh@joeyh.name>
Mon, 30 Aug 2021 20:39:02 +0000 (16:39 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 30 Aug 2021 20:39:02 +0000 (16:39 -0400)
Tests for the reversion fixed in 837116ef1e253f82726b023bfe6ca46777060e27
and similar problems.

Sponsored-by: Dartmouth College's Datalad project
Test.hs
Test/Framework.hs

diff --git a/Test.hs b/Test.hs
index 1ffed562cde8699340da9b3c79c3a5ae401998de..e8a5d83eddc9b8cca536573b5ed552c565d2f83e 100644 (file)
--- a/Test.hs
+++ b/Test.hs
@@ -75,6 +75,7 @@ import qualified BuildInfo
 import qualified Utility.Format
 import qualified Utility.Verifiable
 import qualified Utility.Process
+import qualified Utility.Process.Transcript
 import qualified Utility.Misc
 import qualified Utility.InodeCache
 import qualified Utility.Env
@@ -309,6 +310,7 @@ unitTests :: String -> TestTree
 unitTests note = testGroup ("Unit Tests " ++ note)
        [ testCase "add dup" test_add_dup
        , testCase "add extras" test_add_extras
+       , testCase "readonly" test_readonly
        , testCase "ignore deleted files" test_ignore_deleted_files
        , testCase "metadata" test_metadata
        , testCase "export_import" test_export_import
@@ -427,6 +429,23 @@ test_add_extras = intmpclonerepo $ do
        annexed_present wormannexedfile
        checkbackend wormannexedfile backendWORM
 
+test_readonly :: Assertion
+test_readonly =
+       withtmpclonerepo $ \r1 ->
+               withtmpclonerepo $ \r2 -> do
+                       pair r1 r2
+                       indir r1 $ do
+                               git_annex "get" [annexedfile] "get failed in first repo"
+                       {- chmod may fail, or not be available, or the
+                        - filesystem not support permissions. -}
+                       void $ Utility.Process.Transcript.processTranscript
+                               "chmod" ["-R", "-w", r1] Nothing
+                       indir r2 $ do
+                               git_annex "sync" ["r1", "--no-push"] "sync with readonly repo"
+                               git_annex "get" [annexedfile, "--from", "r1"] "get from readonly repo"
+                               git "remote" ["rm", "origin"] "remote rm"
+                               git_annex "drop" [annexedfile] "drop vs readonly repo"
+
 test_ignore_deleted_files :: Assertion
 test_ignore_deleted_files = intmpclonerepo $ do
        git_annex "get" [annexedfile] "get"
@@ -1640,14 +1659,6 @@ test_adjusted_branch_subtree_regression =
                        git "checkout" [origbranch] "git checkout"
                        doesFileExist "a/b/x/y" @? ("a/b/x/y missing from master after adjusted branch sync")
 
-{- Set up repos as remotes of each other. -}
-pair :: FilePath -> FilePath -> Assertion
-pair r1 r2 = forM_ [r1, r2] $ \r -> indir r $ do
-       when (r /= r1) $
-               git "remote" ["add", "r1", "../../" ++ r1] "remote add"
-       when (r /= r2) $
-               git "remote" ["add", "r2", "../../" ++ r2] "remote add"
-
 test_map :: Assertion
 test_map = intmpclonerepo $ do
        -- set descriptions, that will be looked for in the map
index f5b380f26f2938865bd736ab6052c184c35cb357..73a3ce355b36e45a158d6038c38bc18ac0f9682b 100644 (file)
@@ -631,3 +631,12 @@ origBranch :: Types.Annex String
 origBranch = maybe "foo"
        (Git.Types.fromRef . Git.Ref.base . Annex.AdjustedBranch.fromAdjustedBranch)
        <$> Annex.inRepo Git.Branch.current
+
+{- Set up repos as remotes of each other. -}
+pair :: FilePath -> FilePath -> Assertion
+pair r1 r2 = forM_ [r1, r2] $ \r -> indir r $ do
+       when (r /= r1) $
+               git "remote" ["add", "r1", "../../" ++ r1] "remote add"
+       when (r /= r2) $
+               git "remote" ["add", "r2", "../../" ++ r2] "remote add"
+