2013-11-07 17:55:36 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-09-22 21:32:28 +00:00
|
|
|
- Copyright 2013-2015 Joey Hess <id@joeyh.name>
|
2013-11-07 17:55:36 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Status where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Annex.CatFile
|
|
|
|
import Annex.Content.Direct
|
|
|
|
import Config
|
2015-09-22 21:32:28 +00:00
|
|
|
import Git.Status
|
2013-11-07 17:55:36 +00:00
|
|
|
import qualified Git.Ref
|
2015-09-22 21:32:28 +00:00
|
|
|
import Git.FilePath
|
2013-11-07 17:55:36 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2016-01-20 18:07:13 +00:00
|
|
|
cmd = notBareRepo $ noCommit $ noMessages $
|
|
|
|
withGlobalOptions [jsonOption] $
|
|
|
|
command "status" SectionCommon
|
|
|
|
"show the working tree status"
|
2017-02-20 20:37:04 +00:00
|
|
|
paramPaths (seek <$$> optParser)
|
2013-11-07 17:55:36 +00:00
|
|
|
|
2017-02-20 20:37:04 +00:00
|
|
|
data StatusOptions = StatusOptions
|
|
|
|
{ statusFiles :: CmdParams
|
|
|
|
, ignoreSubmodules :: Maybe String
|
|
|
|
}
|
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser StatusOptions
|
|
|
|
optParser desc = StatusOptions
|
|
|
|
<$> cmdParams desc
|
|
|
|
<*> optional (strOption
|
|
|
|
( long "ignore-submodules"
|
|
|
|
<> help "passed on to git status"
|
|
|
|
<> metavar "WHEN"
|
|
|
|
))
|
|
|
|
|
|
|
|
seek :: StatusOptions -> CommandSeek
|
|
|
|
seek o = withWords (start o) (statusFiles o)
|
2013-11-07 17:55:36 +00:00
|
|
|
|
2017-02-20 20:37:04 +00:00
|
|
|
start :: StatusOptions -> [FilePath] -> CommandStart
|
|
|
|
start o locs = do
|
|
|
|
(l, cleanup) <- inRepo $ getStatus ps locs
|
2013-11-07 17:55:36 +00:00
|
|
|
getstatus <- ifM isDirect
|
|
|
|
( return statusDirect
|
2015-09-22 21:32:28 +00:00
|
|
|
, return $ \s -> pure (Just s)
|
2013-11-07 17:55:36 +00:00
|
|
|
)
|
2015-09-22 21:32:28 +00:00
|
|
|
forM_ l $ \s -> maybe noop displayStatus =<< getstatus s
|
2017-03-02 18:09:42 +00:00
|
|
|
ifM (liftIO cleanup)
|
|
|
|
( stop
|
|
|
|
, giveup "git status failed"
|
|
|
|
)
|
2017-02-20 20:37:04 +00:00
|
|
|
where
|
|
|
|
ps = case ignoreSubmodules o of
|
|
|
|
Nothing -> []
|
|
|
|
Just s -> [Param $ "--ignore-submodules="++s]
|
2013-11-07 17:55:36 +00:00
|
|
|
|
2015-09-22 21:32:28 +00:00
|
|
|
displayStatus :: Status -> Annex ()
|
|
|
|
-- renames not shown in this simplified status
|
|
|
|
displayStatus (Renamed _ _) = noop
|
|
|
|
displayStatus s = do
|
|
|
|
let c = statusChar s
|
|
|
|
absf <- fromRepo $ fromTopFilePath (statusFile s)
|
|
|
|
f <- liftIO $ relPathCwdToFile absf
|
2016-07-26 23:15:34 +00:00
|
|
|
unlessM (showFullJSON $ JSONChunk [("status", [c]), ("file", f)]) $
|
2015-09-22 21:32:28 +00:00
|
|
|
liftIO $ putStrLn $ [c] ++ " " ++ f
|
2013-11-07 17:55:36 +00:00
|
|
|
|
2015-12-19 17:36:40 +00:00
|
|
|
-- Git thinks that present direct mode files are typechanged.
|
|
|
|
-- (On crippled filesystems, git instead thinks they're modified.)
|
|
|
|
-- Check their content to see if they are modified or not.
|
2015-09-22 21:32:28 +00:00
|
|
|
statusDirect :: Status -> Annex (Maybe Status)
|
2015-12-19 17:36:40 +00:00
|
|
|
statusDirect (TypeChanged t) = statusDirect' t
|
|
|
|
statusDirect s@(Modified t) = ifM crippledFileSystem
|
|
|
|
( statusDirect' t
|
|
|
|
, pure (Just s)
|
|
|
|
)
|
|
|
|
statusDirect s = pure (Just s)
|
|
|
|
|
|
|
|
statusDirect' :: TopFilePath -> Annex (Maybe Status)
|
|
|
|
statusDirect' t = do
|
2015-09-22 21:32:28 +00:00
|
|
|
absf <- fromRepo $ fromTopFilePath t
|
|
|
|
f <- liftIO $ relPathCwdToFile absf
|
|
|
|
v <- liftIO (catchMaybeIO $ getFileStatus f)
|
|
|
|
case v of
|
|
|
|
Nothing -> return $ Just $ Deleted t
|
|
|
|
Just s
|
|
|
|
| not (isSymbolicLink s) ->
|
|
|
|
checkkey f s =<< catKeyFile f
|
|
|
|
| otherwise -> Just <$> checkNew f t
|
2014-01-18 16:05:10 +00:00
|
|
|
where
|
2015-09-22 21:32:28 +00:00
|
|
|
checkkey f s (Just k) = ifM (sameFileStatus k f s)
|
2013-11-07 17:55:36 +00:00
|
|
|
( return Nothing
|
2015-09-22 21:32:28 +00:00
|
|
|
, return $ Just $ Modified t
|
2013-11-07 17:55:36 +00:00
|
|
|
)
|
2015-09-22 21:32:28 +00:00
|
|
|
checkkey f _ Nothing = Just <$> checkNew f t
|
2013-11-07 17:55:36 +00:00
|
|
|
|
2015-09-22 21:32:28 +00:00
|
|
|
checkNew :: FilePath -> TopFilePath -> Annex Status
|
|
|
|
checkNew f t = ifM (isJust <$> catObjectDetails (Git.Ref.fileRef f))
|
|
|
|
( return (Modified t)
|
|
|
|
, return (Untracked t)
|
2013-11-07 17:55:36 +00:00
|
|
|
)
|