aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-01-26 16:20:28 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-01-26 16:20:28 -0400
commit7f6af79232eee685daf58e72737c5284f80cf482 (patch)
treee3ec0e7612845e056df355c6841ee9a58e603d52
parent7b2da21ab7bc51785203a69cc05ab811a8629ecb (diff)
trust setting improvements
-rw-r--r--Command/Semitrust.hs4
-rw-r--r--Command/Trust.hs4
-rw-r--r--Command/Untrust.hs4
-rw-r--r--Remotes.hs1
-rw-r--r--Trust.hs2
-rw-r--r--debian/changelog1
-rw-r--r--doc/git-annex.mdwn2
-rw-r--r--test.hs64
8 files changed, 47 insertions, 35 deletions
diff --git a/Command/Semitrust.hs b/Command/Semitrust.hs
index 8ed95f5a3..a91d25359 100644
--- a/Command/Semitrust.hs
+++ b/Command/Semitrust.hs
@@ -21,11 +21,11 @@ command = [Command "semitrust" (paramRepeating paramRemote) seek
seek :: [CommandSeek]
seek = [withString start]
-{- Marks a remote as not trusted. -}
start :: CommandStartString
start name = do
+ showStart "semitrust" name
+ Remotes.readConfigs
r <- Remotes.byName name
- showStart "untrust" name
return $ Just $ perform r
perform :: Git.Repo -> CommandPerform
diff --git a/Command/Trust.hs b/Command/Trust.hs
index a40c8dccc..3fbff68b8 100644
--- a/Command/Trust.hs
+++ b/Command/Trust.hs
@@ -21,11 +21,11 @@ command = [Command "trust" (paramRepeating paramRemote) seek
seek :: [CommandSeek]
seek = [withString start]
-{- Marks a remote as trusted. -}
start :: CommandStartString
start name = do
- r <- Remotes.byName name
showStart "trust" name
+ Remotes.readConfigs
+ r <- Remotes.byName name
return $ Just $ perform r
perform :: Git.Repo -> CommandPerform
diff --git a/Command/Untrust.hs b/Command/Untrust.hs
index 9e884e812..69d0ab391 100644
--- a/Command/Untrust.hs
+++ b/Command/Untrust.hs
@@ -21,11 +21,11 @@ command = [Command "untrust" (paramRepeating paramRemote) seek
seek :: [CommandSeek]
seek = [withString start]
-{- Marks a remote as not trusted. -}
start :: CommandStartString
start name = do
- r <- Remotes.byName name
showStart "untrust" name
+ Remotes.readConfigs
+ r <- Remotes.byName name
return $ Just $ perform r
perform :: Git.Repo -> CommandPerform
diff --git a/Remotes.hs b/Remotes.hs
index e8a78a59e..fe5b7f767 100644
--- a/Remotes.hs
+++ b/Remotes.hs
@@ -222,6 +222,7 @@ same a b = Git.repoRemoteName a == Git.repoRemoteName b
{- Looks up a remote by name. -}
byName :: String -> Annex Git.Repo
+byName "." = Annex.gitRepo -- special case to refer to current repository
byName name = do
when (null name) $ error "no remote specified"
g <- Annex.gitRepo
diff --git a/Trust.hs b/Trust.hs
index 9474d47d7..695059a93 100644
--- a/Trust.hs
+++ b/Trust.hs
@@ -73,6 +73,8 @@ trustMapParse s = M.fromList $ map pair $ filter (not . null) $ lines s
{- Changes the trust level for a uuid in the trustLog, and commits it. -}
trustSet :: UUID -> TrustLevel -> Annex ()
trustSet uuid level = do
+ when (null uuid) $
+ error "unknown UUID; cannot modify trust level"
m <- trustMap
when (M.lookup uuid m /= Just level) $ do
let m' = M.insert uuid level m
diff --git a/debian/changelog b/debian/changelog
index 529a0896b..8b863b947 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,7 @@ git-annex (0.19) UNRELEASED; urgency=low
* There are now three levels of repository trust.
* untrust: Now marks the current repository as untrusted.
* semitrust: Now restores the default trust level. (What untrust used to do.)
+ * fsck: Warn if content is only in untrusted repositories.
-- Joey Hess <joeyh@debian.org> Wed, 19 Jan 2011 18:07:51 -0400
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 9c2be8dc9..d2cde35a0 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -186,6 +186,8 @@ Many git-annex commands will stage changes for later `git commit` by you.
Records that a repository is [[trusted|trust]] to not unexpectedly lose
content. Use with care.
+ To trust the current repository, use "."
+
* untrust [repository ...]
Records that a repository is [[not trusted|trust]] and could lose content
diff --git a/test.hs b/test.hs
index c5e755966..817b1bafb 100644
--- a/test.hs
+++ b/test.hs
@@ -42,7 +42,7 @@ import qualified Command.DropUnused
main :: IO ()
main = do
prepare
- r <- runVerboseTests $ TestList [quickchecks, toplevels]
+ r <- runVerboseTests $ TestList [quickcheck, blackbox]
cleanup tmpdir
propigate r
@@ -51,8 +51,8 @@ propigate (Counts { errors = e }, _)
| e > 0 = error "failed"
| otherwise = return ()
-quickchecks :: Test
-quickchecks = TestLabel "quickchecks" $ TestList
+quickcheck :: Test
+quickcheck = TestLabel "quickcheck" $ TestList
[ qctest "prop_idempotent_deencode" Git.prop_idempotent_deencode
, qctest "prop_idempotent_fileKey" Locations.prop_idempotent_fileKey
, qctest "prop_idempotent_key_read_show" BackendTypes.prop_idempotent_key_read_show
@@ -62,8 +62,8 @@ quickchecks = TestLabel "quickchecks" $ TestList
, qctest "prop_relPathDirToDir_basics" Utility.prop_relPathDirToDir_basics
]
-toplevels :: Test
-toplevels = TestLabel "toplevel" $ TestList
+blackbox :: Test
+blackbox = TestLabel "blackbox" $ TestList
-- test order matters, later tests may rely on state from earlier
[ test_init
, test_add
@@ -290,38 +290,44 @@ test_fix = "git-annex fix" ~: intmpclonerepo $ do
test_trust :: Test
test_trust = "git-annex trust/untrust/semitrust" ~: intmpclonerepo $ do
- trustcheck Trust.SemiTrusted
- git_annex "trust" ["-q", "origin"] @? "trust failed"
- trustcheck Trust.Trusted
- git_annex "trust" ["-q", "origin"] @? "trust of trusted failed"
- trustcheck Trust.Trusted
- git_annex "untrust" ["-q", "origin"] @? "untrust failed"
- trustcheck Trust.UnTrusted
- git_annex "untrust" ["-q", "origin"] @? "untrust of untrusted failed"
- trustcheck Trust.UnTrusted
- git_annex "semitrust" ["-q", "origin"] @? "semitrust failed"
- trustcheck Trust.SemiTrusted
- git_annex "semitrust" ["-q", "origin"] @? "semitrust of semitrusted failed"
- trustcheck Trust.SemiTrusted
+ git_annex "trust" ["-q", repo] @? "trust failed"
+ trustcheck Trust.Trusted "trusted 1"
+ git_annex "trust" ["-q", repo] @? "trust of trusted failed"
+ trustcheck Trust.Trusted "trusted 2"
+ git_annex "untrust" ["-q", repo] @? "untrust failed"
+ trustcheck Trust.UnTrusted "untrusted 1"
+ git_annex "untrust" ["-q", repo] @? "untrust of untrusted failed"
+ trustcheck Trust.UnTrusted "untrusted 2"
+ git_annex "semitrust" ["-q", repo] @? "semitrust failed"
+ trustcheck Trust.SemiTrusted "semitrusted 1"
+ git_annex "semitrust" ["-q", repo] @? "semitrust of semitrusted failed"
+ trustcheck Trust.SemiTrusted "semitrusted 2"
where
- trustcheck expected = do
+ trustcheck expected msg = do
present <- annexeval $ do
+ Remotes.readConfigs
l <- Trust.trustGet expected
- r <- Remotes.byName "origin"
+ r <- Remotes.byName repo
u <- UUID.getUUID r
return $ elem u l
- assertEqual ("trust value " ++ show expected) True present
+ assertBool msg present
+ repo = "origin"
test_fsck :: Test
-test_fsck = "git-annex fsck" ~: intmpclonerepo $ do
- git_annex "fsck" ["-q"] @? "fsck failed"
- Utility.boolSystem "git" ["config", "annex.numcopies", "2"] @? "git config failed"
- r <- git_annex "fsck" ["-q"]
- not r @? "fsck failed to fail with numcopies unsatisfied"
- Utility.boolSystem "git" ["config", "annex.numcopies", "1"] @? "git config failed"
- corrupt annexedfile
- corrupt sha1annexedfile
+test_fsck = "git-annex fsck" ~: TestList [basicfsck, withlocaluntrusted]
where
+ basicfsck = TestCase $ intmpclonerepo $ do
+ git_annex "fsck" ["-q"] @? "fsck failed"
+ Utility.boolSystem "git" ["config", "annex.numcopies", "2"] @? "git config failed"
+ r <- git_annex "fsck" ["-q"]
+ not r @? "fsck failed to fail with numcopies unsatisfied"
+ Utility.boolSystem "git" ["config", "annex.numcopies", "1"] @? "git config failed"
+ corrupt annexedfile
+ corrupt sha1annexedfile
+ withlocaluntrusted = TestCase $ intmpcopyrepo $ do
+ git_annex "untrust" ["-q", "."] @? "untrust of current repo failed"
+ r <- git_annex "fsck" ["-q"]
+ not r @? "fsck failed to fail with content only available in untrusted (current) repository"
corrupt f = do
git_annex "get" ["-q", f] @? "get of file failed"
Content.allowWrite f