fix handling of staged unlocked files
This commit is contained in:
parent
55720885ae
commit
2ab448276c
1 changed files with 25 additions and 10 deletions
|
@ -11,6 +11,7 @@ import Control.Monad.State (liftIO)
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.Posix.Files
|
import System.Posix.Files
|
||||||
|
|
||||||
|
import Types
|
||||||
import Command
|
import Command
|
||||||
import Messages
|
import Messages
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
@ -19,15 +20,8 @@ import qualified GitRepo as Git
|
||||||
{- Undo unlock -}
|
{- Undo unlock -}
|
||||||
start :: SubCmdStartString
|
start :: SubCmdStartString
|
||||||
start file = do
|
start file = do
|
||||||
-- Want to avoid calling git checkout on files that are not
|
locked <- isLocked file
|
||||||
-- annexed -- but without the symlink to the annex, cannot tell
|
if locked
|
||||||
-- 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)
|
|
||||||
then return Nothing
|
then return Nothing
|
||||||
else do
|
else do
|
||||||
showStart "lock" file
|
showStart "lock" file
|
||||||
|
@ -37,5 +31,26 @@ perform :: FilePath -> SubCmdPerform
|
||||||
perform file = do
|
perform file = do
|
||||||
liftIO $ removeFile file
|
liftIO $ removeFile file
|
||||||
g <- Annex.gitRepo
|
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
|
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"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue