% Copyright (C) 2002-2004 David Roundy
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; see the file COPYING. If not, write to
% the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
% Boston, MA 02110-1301, USA.
\darcsCommand{remove}
\begin{code}

{-# OPTIONS_GHC -cpp #-}{-# LANGUAGE CPP #-}moduleDarcs.Commands.Remove(remove,rm,unadd)whereimportControl.Monad(when)importDarcs.Commands(DarcsCommand(..),nodefaults,commandAlias,commandStub,putWarning)importDarcs.Arguments(DarcsFlag(Recursive),fixSubPaths,listRegisteredFiles,workingRepoDir,umaskOption,recursive)importDarcs.RepoPath(SubPath,sp2fn)importDarcs.Repository(Repository,withRepoLock,($-),amInRepository,add_to_pending,readRecordedAndPending,readUnrecorded)importDarcs.Diff(treeDiff)importDarcs.Patch(RepoPatch,Prim,adddir,rmdir,addfile,rmfile)importDarcs.Patch.FileName(fn2fp)importDarcs.Witnesses.Ordered(FL(..),(+>+))importDarcs.Witnesses.Sealed(Sealed(..))importDarcs.Repository.Prefs(filetypeFunction)importStorage.Hashed.Tree(TreeItem(..),find,modifyTree,expand)importStorage.Hashed.AnchoredPath(anchorPath)importStorage.Hashed(floatPath)importDarcs.Commands.Add(expandDirs)importPrinter(text)#include "gadts.h"removeDescription::StringremoveDescription="Remove files from version control."removeHelp::StringremoveHelp="The `darcs remove' command exists primarily for symmetry with `darcs\n"++"add', as the normal way to remove a file from version control is\n"++"simply to delete it from the working tree. This command is only\n"++"useful in the unusual case where one wants to record a removal patch\n"++"WITHOUT deleting the copy in the working tree (which can be re-added).\n"++"\n"++"Note that applying a removal patch to a repository (e.g. by pulling\n"++"the patch) will ALWAYS affect the working tree of that repository.\n"remove::DarcsCommandremove=DarcsCommand{commandName="remove",commandHelp=removeHelp,commandDescription=removeDescription,commandExtraArgs=-1,commandExtraArgHelp=["<FILE or DIRECTORY> ..."],commandCommand=removeCmd,commandPrereq=amInRepository,commandGetArgPossibilities=listRegisteredFiles,commandArgdefaults=nodefaults,commandAdvancedOptions=[umaskOption],commandBasicOptions=[workingRepoDir,recursive"recurse into subdirectories"]}removeCmd::[DarcsFlag]->[String]->IO()removeCmdoptsrelargs=withRepoLockopts$-\repository->doorigfiles<-fixSubPathsoptsrelargsargs<-ifRecursive`elem`optsthenreverse`fmap`expandDirsorigfileselsereturnorigfileswhen(nullargs)$putStrLn"Nothing specified, nothing removed."Sealedp<-makeRemovePatchoptsrepositoryargsadd_to_pendingrepositorypmakeRemovePatch::RepoPatchp=>[DarcsFlag]->RepositorypC(rut)->[SubPath]->IO(Sealed(FLPrimC(u)))makeRemovePatchoptsrepositoryfiles=dorecorded<-expand=<<readRecordedAndPendingrepositoryunrecorded<-readUnrecordedrepositoryftf<-filetypeFunctionmrpftfrecordedunrecorded$map(floatPath.fn2fp.sp2fn)fileswheremrpftfrecordedunrecorded(f:fs)=doletrecorded'=modifyTreerecordedfNothingunrecorded'=modifyTreeunrecordedfNothingSealedrest<-mrpftfrecorded'unrecorded'fsletf_fp=anchorPath""fcase(findrecordedf,findunrecordedf)of(Just(SubTree_),Just(SubTree_))->return.Sealed$rmdirf_fp:>:rest(Just(File_),Just(File_))->dodiff<-treeDiffftfunrecordedunrecorded'return.Sealed$diff+>+rest(Just(File_),_)->return.Sealed$addfilef_fp:>:rmfilef_fp:>:rest(Just(SubTree_),_)->return.Sealed$adddirf_fp:>:rmdirf_fp:>:rest(_,_)->doputWarningopts.text$"Can't remove "++f_fpreturn$Sealedrestmrp___[]=return(SealedNilFL)rmDescription::StringrmDescription="Help newbies find `darcs remove'."rmHelp::StringrmHelp="The `darcs rm' command does nothing.\n"++"\n"++"The normal way to remove a file from version control is simply to\n"++"delete it from the working tree. To remove a file from version\n"++"control WITHOUT affecting the working tree, see `darcs remove'.\n"rm::DarcsCommandrm=commandStub"rm"rmHelprmDescriptionremoveunadd::DarcsCommandunadd=commandAlias"unadd"remove