fix handling of staged unlocked files

This commit is contained in:
Joey Hess 2010-11-10 13:01:01 -04:00
parent 55720885ae
commit 2ab448276c

View file

@ -11,6 +11,7 @@ import Control.Monad.State (liftIO)
import System.Directory
import System.Posix.Files
import Types
import Command
import Messages
import qualified Annex
@ -19,15 +20,8 @@ import qualified GitRepo as Git
{- Undo unlock -}
start :: SubCmdStartString
start file = do
-- Want to avoid calling git checkout on files that are not
-- annexed -- but without the symlink to the annex, cannot tell
-- for sure if the file was annexed. So, check if git thinks the
-- file's type has changed (from a symlink to a regular file).
g <- Annex.gitRepo
test <- liftIO $
Git.pipeRead g ["diff", "--name-only", "--diff-filter=T", file]
s <- liftIO $ getSymbolicLinkStatus file
if (null test || isSymbolicLink s)
locked <- isLocked file
if locked
then return Nothing
else do
showStart "lock" file
@ -37,5 +31,26 @@ perform :: FilePath -> SubCmdPerform
perform file = do
liftIO $ removeFile file
g <- Annex.gitRepo
liftIO $ Git.run g ["checkout", file]
-- first reset the file to drop any changes checked into the index
liftIO $ Git.run g ["reset", "-q", "--", file]
-- checkout the symlink
liftIO $ Git.run g ["checkout", "--", file]
return $ Just $ return True -- no cleanup needed
{- Checks if a file is unlocked for edit.
-
- But, without the symlink to the annex, cannot tell for sure if the
- file was annexed before. So, check if git thinks the file's type has
- changed (from a symlink to a regular file). -}
isLocked :: FilePath -> Annex Bool
isLocked file = do
g <- Annex.gitRepo
changed <- typechanged g Nothing
changedCached <- typechanged g $ Just "--cached"
s <- liftIO $ getSymbolicLinkStatus file
return $ null (changed++changedCached) || isSymbolicLink s
where
typechanged g Nothing = typechanged' g params
typechanged g (Just param) = typechanged' g $ params++[param]
typechanged' g p = liftIO $ Git.pipeRead g $ p++[file]
params = ["diff", "--name-only", "--diff-filter=T"]