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
|
2015-09-22 21:32:28 +00:00
|
|
|
import Git.Status
|
|
|
|
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 $
|
2022-06-29 17:28:08 +00:00
|
|
|
withAnnexOptions [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
|
2019-08-26 19:52:19 +00:00
|
|
|
let getstatus = pure . simplifiedStatus
|
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)
|
2020-11-02 20:31:28 +00:00
|
|
|
f <- liftIO $ fromRawFilePath <$> 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
|