1 % Copyright (C) 2002-2005 David Roundy
3 % This program is free software; you can redistribute it and/or modify
4 % it under the terms of the GNU General Public License as published by
5 % the Free Software Foundation; either version 2, or (at your option)
8 % This program is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 % GNU General Public License for more details.
13 % You should have received a copy of the GNU General Public License
14 % along with this program; see the file COPYING. If not, write to
15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 % Boston, MA 02110-1301, USA.
18 \subsection{darcs check}
20 module Darcs.Commands.Check ( check ) where
21 import Control.Monad ( when, unless )
22 import System.Exit ( ExitCode(..), exitWith )
24 import Darcs.Commands ( DarcsCommand(..), nodefaults )
25 import Darcs.Arguments ( DarcsFlag( Quiet, NoTest ),
26 partial_check, notest,
27 leave_test_dir, working_repo_dir,
29 import Darcs.Repository.Repair( replayRepository, cleanupRepositoryReplay,
30 RepositoryConsistency(..), CanRepair(..) )
31 import Darcs.Repository ( Repository, amInRepository, withRepository, ($-), slurp_recorded,
33 import Darcs.Patch ( RepoPatch, showPatch )
34 import Darcs.Ordered ( FL(..) )
35 import Darcs.Diff ( unsafeDiff )
36 import Darcs.Repository.Prefs ( filetype_function )
37 import Printer ( putDocLn, text, ($$), (<+>) )
42 \haskell{check_description}
44 check_description :: String
45 check_description = "Check the repository for consistency."
47 Check verifies that the patches stored in the repository, when successively
48 applied to an empty tree, properly recreate the stored pristine tree.
54 If you have a checkpoint of the repository (as is the case if you got the
55 repository originally using \verb!darcs get --partial!), by default
57 will only verify the contents since the most recent checkpoint. You can
58 change this behavior using the \verb!--complete! flag.
63 "Check verifies that the patches stored in the repository, when successively\n"++
64 "applied to an empty tree, properly recreate the stored pristine tree.\n"
69 check = DarcsCommand {command_name = "check",
70 command_help = check_help,
71 command_description = check_description,
72 command_extra_args = 0,
73 command_extra_arg_help = [],
74 command_command = check_cmd,
75 command_prereq = amInRepository,
76 command_get_arg_possibilities = return [],
77 command_argdefaults = nodefaults,
78 command_advanced_options = [],
79 command_basic_options = [partial_check,
87 check_cmd :: [DarcsFlag] -> [String] -> IO ()
88 check_cmd opts _ = withRepository opts $- \repo -> check' repo opts
90 check' :: (RepoPatch p) => Repository p -> [DarcsFlag] -> IO ()
91 check' repository opts = do
92 let putInfo s = when (not $ Quiet `elem` opts) $ putDocLn s
93 state <- replayRepository CannotRepair repository opts
95 RepositoryConsistent -> do
96 putInfo $ text "The repository is consistent!"
97 unless (NoTest `elem` opts) $ testTentative repository
99 RepositoryInconsistent newpris -> do
100 putInfo $ text "Looks like we have a difference..."
101 mc <- slurp_recorded repository
102 ftf <- filetype_function
103 putInfo $ case unsafeDiff opts ftf newpris mc of
104 NilFL -> text "Nothing"
105 patch -> text "Difference: " <+> showPatch patch
107 $$ text "Inconsistent repository!"
109 where done r = do cleanupRepositoryReplay repository
113 \input{Darcs/Test.lhs}
119 If you just want to check the consistency of your repository without
120 running the test, you can call darcs check with the \verb!--no-test!