summaryrefslogtreecommitdiff
path: root/Commands.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-16 21:15:23 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-16 21:15:23 -0400
commit0c0ae028386aaf17aed1771eee6731c62b72e839 (patch)
tree46ea744828ebbabbef97d996639aa47f9bff191a /Commands.hs
parentb02a3b3f5b264ca12fcbf225db3c3ddd341ac51a (diff)
add fix subcommand
Diffstat (limited to 'Commands.hs')
-rw-r--r--Commands.hs20
1 files changed, 15 insertions, 5 deletions
diff --git a/Commands.hs b/Commands.hs
index 8afe66b91..9a3f92524 100644
--- a/Commands.hs
+++ b/Commands.hs
@@ -24,7 +24,8 @@ import Core
import qualified Remotes
import qualified BackendTypes
-data CmdWants = FilesInGit | FilesNotInGit | RepoName | SingleString
+data CmdWants = FilesInGit | FilesNotInGit | FilesInOrNotInGit |
+ RepoName | SingleString
data Command = Command {
cmdname :: String,
cmdaction :: (String -> Annex ()),
@@ -40,7 +41,7 @@ cmds = [
, (Command "pull" pullCmd RepoName)
, (Command "unannex" unannexCmd FilesInGit)
, (Command "describe" describeCmd SingleString)
- , (Command "fix" fixCmd FilesInGit)
+ , (Command "fix" fixCmd FilesInOrNotInGit)
]
options = [
@@ -57,6 +58,10 @@ findWanted FilesNotInGit params repo = do
findWanted FilesInGit params repo = do
files <- mapM (Git.inRepo repo) params
return $ foldl (++) [] files
+findWanted FilesInOrNotInGit params repo = do
+ a <- findWanted FilesInGit params repo
+ b <- findWanted FilesNotInGit params repo
+ return $ union a b
findWanted SingleString params _ = do
return $ [unwords params]
findWanted RepoName params _ = do
@@ -178,20 +183,25 @@ dropCmd file = notinBackend file err $ \(key, backend) -> do
{- Fixes the symlink to an annexed file. -}
fixCmd :: String -> Annex ()
fixCmd file = notinBackend file err $ \(key, backend) -> do
+ liftIO $ putStrLn $ "fix " ++ file
link <- calcGitLink file key
- checkLegal file
+ checkLegal file link
liftIO $ createDirectoryIfMissing True (parentDir file)
liftIO $ removeFile file
liftIO $ createSymbolicLink link file
gitAdd file $ Just $ "git-annex fix " ++ file
where
- checkLegal file = do
+ checkLegal file link = do
s <- liftIO $ getSymbolicLinkStatus file
force <- Annex.flagIsSet Force
if (not (isSymbolicLink s) && not force)
then error $ "not a symbolic link : " ++ file ++
" (use --force to override this sanity check)"
- else return ()
+ else do
+ l <- liftIO $ readSymbolicLink file
+ if (link == l)
+ then error $ "symbolic link already ok for: " ++ file
+ else return ()
err = error $ "not annexed " ++ file
{- Pushes all files to a remote repository. -}