don't complain if a file is not annexed
This commit is contained in:
parent
97b20e7ffe
commit
e602238cd8
1 changed files with 14 additions and 19 deletions
33
Commands.hs
33
Commands.hs
|
@ -101,7 +101,7 @@ parseCmd argv state = do
|
||||||
{- Annexes a file, storing it in a backend, and then moving it into
|
{- Annexes a file, storing it in a backend, and then moving it into
|
||||||
- the annex directory and setting up the symlink pointing to its content. -}
|
- the annex directory and setting up the symlink pointing to its content. -}
|
||||||
addCmd :: FilePath -> Annex ()
|
addCmd :: FilePath -> Annex ()
|
||||||
addCmd file = inBackend file err $ do
|
addCmd file = inBackend file $ do
|
||||||
liftIO $ checkLegal file
|
liftIO $ checkLegal file
|
||||||
showStart "add" file
|
showStart "add" file
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
|
@ -112,7 +112,6 @@ addCmd file = inBackend file err $ do
|
||||||
logStatus key ValuePresent
|
logStatus key ValuePresent
|
||||||
setup g key
|
setup g key
|
||||||
where
|
where
|
||||||
err = error $ "already annexed " ++ file
|
|
||||||
checkLegal file = do
|
checkLegal file = do
|
||||||
s <- getSymbolicLinkStatus file
|
s <- getSymbolicLinkStatus file
|
||||||
if ((isSymbolicLink s) || (not $ isRegularFile s))
|
if ((isSymbolicLink s) || (not $ isRegularFile s))
|
||||||
|
@ -129,7 +128,7 @@ addCmd file = inBackend file err $ do
|
||||||
|
|
||||||
{- Undo addCmd. -}
|
{- Undo addCmd. -}
|
||||||
unannexCmd :: FilePath -> Annex ()
|
unannexCmd :: FilePath -> Annex ()
|
||||||
unannexCmd file = notinBackend file err $ \(key, backend) -> do
|
unannexCmd file = notinBackend file $ \(key, backend) -> do
|
||||||
showStart "unannex" file
|
showStart "unannex" file
|
||||||
Annex.flagChange Force True -- force backend to always remove
|
Annex.flagChange Force True -- force backend to always remove
|
||||||
Backend.removeKey backend key
|
Backend.removeKey backend key
|
||||||
|
@ -138,7 +137,6 @@ unannexCmd file = notinBackend file err $ \(key, backend) -> do
|
||||||
let src = annexLocation g key
|
let src = annexLocation g key
|
||||||
moveout g src
|
moveout g src
|
||||||
where
|
where
|
||||||
err = error $ "not annexed " ++ file
|
|
||||||
moveout g src = do
|
moveout g src = do
|
||||||
nocommit <- Annex.flagIsSet NoCommit
|
nocommit <- Annex.flagIsSet NoCommit
|
||||||
liftIO $ removeFile file
|
liftIO $ removeFile file
|
||||||
|
@ -156,7 +154,7 @@ unannexCmd file = notinBackend file err $ \(key, backend) -> do
|
||||||
|
|
||||||
{- Gets an annexed file from one of the backends. -}
|
{- Gets an annexed file from one of the backends. -}
|
||||||
getCmd :: FilePath -> Annex ()
|
getCmd :: FilePath -> Annex ()
|
||||||
getCmd file = notinBackend file err $ \(key, backend) -> do
|
getCmd file = notinBackend file $ \(key, backend) -> do
|
||||||
inannex <- inAnnex key
|
inannex <- inAnnex key
|
||||||
if (inannex)
|
if (inannex)
|
||||||
then return ()
|
then return ()
|
||||||
|
@ -174,13 +172,11 @@ getCmd file = notinBackend file err $ \(key, backend) -> do
|
||||||
showEndOk
|
showEndOk
|
||||||
else do
|
else do
|
||||||
showEndFail "get" file
|
showEndFail "get" file
|
||||||
where
|
|
||||||
err = error $ "not annexed " ++ file
|
|
||||||
|
|
||||||
{- Indicates a file's content is not wanted anymore, and should be removed
|
{- Indicates a file's content is not wanted anymore, and should be removed
|
||||||
- if it's safe to do so. -}
|
- if it's safe to do so. -}
|
||||||
dropCmd :: FilePath -> Annex ()
|
dropCmd :: FilePath -> Annex ()
|
||||||
dropCmd file = notinBackend file err $ \(key, backend) -> do
|
dropCmd file = notinBackend file $ \(key, backend) -> do
|
||||||
inbackend <- Backend.hasKey key
|
inbackend <- Backend.hasKey key
|
||||||
if (not inbackend)
|
if (not inbackend)
|
||||||
then return () -- no-op
|
then return () -- no-op
|
||||||
|
@ -203,15 +199,14 @@ dropCmd file = notinBackend file err $ \(key, backend) -> do
|
||||||
liftIO $ removeFile loc
|
liftIO $ removeFile loc
|
||||||
return ()
|
return ()
|
||||||
else return ()
|
else return ()
|
||||||
err = error $ "not annexed " ++ file
|
|
||||||
|
|
||||||
{- Fixes the symlink to an annexed file. -}
|
{- Fixes the symlink to an annexed file. -}
|
||||||
fixCmd :: String -> Annex ()
|
fixCmd :: String -> Annex ()
|
||||||
fixCmd file = notinBackend file skip $ \(key, backend) -> do
|
fixCmd file = notinBackend file $ \(key, backend) -> do
|
||||||
link <- calcGitLink file key
|
link <- calcGitLink file key
|
||||||
l <- liftIO $ readSymbolicLink file
|
l <- liftIO $ readSymbolicLink file
|
||||||
if (link == l)
|
if (link == l)
|
||||||
then skip
|
then return ()
|
||||||
else do
|
else do
|
||||||
showStart "fix" file
|
showStart "fix" file
|
||||||
liftIO $ createDirectoryIfMissing True (parentDir file)
|
liftIO $ createDirectoryIfMissing True (parentDir file)
|
||||||
|
@ -219,10 +214,6 @@ fixCmd file = notinBackend file skip $ \(key, backend) -> do
|
||||||
liftIO $ createSymbolicLink link file
|
liftIO $ createSymbolicLink link file
|
||||||
gitAdd file $ Just $ "git-annex fix " ++ file
|
gitAdd file $ Just $ "git-annex fix " ++ file
|
||||||
showEndOk
|
showEndOk
|
||||||
where
|
|
||||||
-- quietly skip non-annexed files, so this can be used
|
|
||||||
-- as a commit hook
|
|
||||||
skip = return ()
|
|
||||||
|
|
||||||
{- Stores description for the repository. -}
|
{- Stores description for the repository. -}
|
||||||
initCmd :: String -> Annex ()
|
initCmd :: String -> Annex ()
|
||||||
|
@ -240,9 +231,13 @@ initCmd description = do
|
||||||
liftIO $ putStrLn "description set"
|
liftIO $ putStrLn "description set"
|
||||||
|
|
||||||
-- helpers
|
-- helpers
|
||||||
inBackend file yes no = do
|
inBackend file a = do
|
||||||
r <- Backend.lookupFile file
|
r <- Backend.lookupFile file
|
||||||
case (r) of
|
case (r) of
|
||||||
Just v -> yes v
|
Just v -> return ()
|
||||||
Nothing -> no
|
Nothing -> a
|
||||||
notinBackend file yes no = inBackend file no yes
|
notinBackend file a = do
|
||||||
|
r <- Backend.lookupFile file
|
||||||
|
case (r) of
|
||||||
|
Just v -> a v
|
||||||
|
Nothing -> return ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue