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.
This commit is contained in:
Joey Hess 2018-05-14 16:51:06 -04:00
parent d7021d420f
commit 442e607b0a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 68 additions and 31 deletions

View file

@ -43,8 +43,8 @@ start :: StatusOptions -> [FilePath] -> CommandStart
start o locs = do
(l, cleanup) <- inRepo $ getStatus ps locs
getstatus <- ifM isDirect
( return statusDirect
, return $ \s -> pure (Just s)
( return (maybe (pure Nothing) statusDirect . simplifiedStatus)
, return (pure . simplifiedStatus)
)
forM_ l $ \s -> maybe noop displayStatus =<< getstatus s
ifM (liftIO cleanup)
@ -56,10 +56,16 @@ start o locs = do
Nothing -> []
Just s -> [Param $ "--ignore-submodules="++s]
-- 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
displayStatus :: Status -> Annex ()
-- renames not shown in this simplified status
-- Renames not shown in this simplified status
displayStatus (Renamed _ _) = noop
displayStatus s = do
displayStatus s = do
let c = statusChar s
absf <- fromRepo $ fromTopFilePath (statusFile s)
f <- liftIO $ relPathCwdToFile absf