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
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-11-07 17:55:36 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
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 $
|
2018-02-19 18:28:17 +00:00
|
|
|
withGlobalOptions [jsonOptions] $
|
2016-01-20 18:07:13 +00:00
|
|
|
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
|
2018-10-01 18:12:06 +00:00
|
|
|
seek o = withWords (commandAction . 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
|
Don't allow entering a view with staged or unstaged changes.
In some cases, unstaged changes are safe, eg dotfiles in the top which
are not affected by a view. Or non-annexed files in general which would
prevent view branch checkout from proceeding. But in other cases,
particularly unstaged changes to annexed files, entering a view would wipe
out those changes! And so don't allow entering a view with any unstaged
changes.
Staged changes are not safe when entering a view, because the changes get
committed to the view branch, and so the user is unlikely to remember them
when they exit the view, and so will effectively lose them, even if they're
still present in the view branch.
Also, improved the git status parser, although the improvement turned out
to not really be needed.
This commit was sponsored by Eric Drechsel on Patreon.
2018-05-14 20:51:06 +00:00
|
|
|
( return (maybe (pure Nothing) statusDirect . simplifiedStatus)
|
|
|
|
, return (pure . simplifiedStatus)
|
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
|
|
|
|
Don't allow entering a view with staged or unstaged changes.
In some cases, unstaged changes are safe, eg dotfiles in the top which
are not affected by a view. Or non-annexed files in general which would
prevent view branch checkout from proceeding. But in other cases,
particularly unstaged changes to annexed files, entering a view would wipe
out those changes! And so don't allow entering a view with any unstaged
changes.
Staged changes are not safe when entering a view, because the changes get
committed to the view branch, and so the user is unlikely to remember them
when they exit the view, and so will effectively lose them, even if they're
still present in the view branch.
Also, improved the git status parser, although the improvement turned out
to not really be needed.
This commit was sponsored by Eric Drechsel on Patreon.
2018-05-14 20:51:06 +00:00
|
|
|
-- Prefer to show unstaged status in this simplified status.
|
|
|
|
simplifiedStatus :: StagedUnstaged Status -> Maybe Status
|
|
|
|
simplifiedStatus (StagedUnstaged { unstaged = Just s }) = Just s
|
|
|
|
simplifiedStatus (StagedUnstaged { staged = Just s }) = Just s
|
|
|
|
simplifiedStatus _ = Nothing
|
|
|
|
|
2015-09-22 21:32:28 +00:00
|
|
|
displayStatus :: Status -> Annex ()
|
Don't allow entering a view with staged or unstaged changes.
In some cases, unstaged changes are safe, eg dotfiles in the top which
are not affected by a view. Or non-annexed files in general which would
prevent view branch checkout from proceeding. But in other cases,
particularly unstaged changes to annexed files, entering a view would wipe
out those changes! And so don't allow entering a view with any unstaged
changes.
Staged changes are not safe when entering a view, because the changes get
committed to the view branch, and so the user is unlikely to remember them
when they exit the view, and so will effectively lose them, even if they're
still present in the view branch.
Also, improved the git status parser, although the improvement turned out
to not really be needed.
This commit was sponsored by Eric Drechsel on Patreon.
2018-05-14 20:51:06 +00:00
|
|
|
-- Renames not shown in this simplified status
|
2015-09-22 21:32:28 +00:00
|
|
|
displayStatus (Renamed _ _) = noop
|
Don't allow entering a view with staged or unstaged changes.
In some cases, unstaged changes are safe, eg dotfiles in the top which
are not affected by a view. Or non-annexed files in general which would
prevent view branch checkout from proceeding. But in other cases,
particularly unstaged changes to annexed files, entering a view would wipe
out those changes! And so don't allow entering a view with any unstaged
changes.
Staged changes are not safe when entering a view, because the changes get
committed to the view branch, and so the user is unlikely to remember them
when they exit the view, and so will effectively lose them, even if they're
still present in the view branch.
Also, improved the git status parser, although the improvement turned out
to not really be needed.
This commit was sponsored by Eric Drechsel on Patreon.
2018-05-14 20:51:06 +00:00
|
|
|
displayStatus s = do
|
2015-09-22 21:32:28 +00:00
|
|
|
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
|
|
|
)
|