summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-10 13:01:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-10 13:01:01 -0400
commit2ab448276c90cfb588b8608c2e84ebbe88c87e57 (patch)
treea88f549d3ce0be9c5b88bd4cd82cb38f147d0da4
parent55720885aeb90e9b8d3e4153145b6a13cac1c0c7 (diff)
fix handling of staged unlocked files
-rw-r--r--Command/Lock.hs35
1 files changed, 25 insertions, 10 deletions
diff --git a/Command/Lock.hs b/Command/Lock.hs
index c28e64327..1be35d612 100644
--- a/Command/Lock.hs
+++ b/Command/Lock.hs
@@ -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"]