git-annex/Command/VPop.hs

51 lines
1.2 KiB
Haskell
Raw Normal View History

{- git-annex command
-
- Copyright 2014 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.VPop where
import Common.Annex
import Command
import qualified Git
import qualified Git.Command
import qualified Git.Ref
import Types.View
import Logs.View
import Command.View (checkoutViewBranch)
cmd :: [Command]
cmd = [notBareRepo $ notDirect $
2014-02-19 18:55:34 +00:00
command "vpop" (paramOptional paramNumber) seek SectionMetaData
"switch back to previous view"]
seek :: CommandSeek
2014-02-19 01:57:21 +00:00
seek = withWords start
2014-02-19 01:57:21 +00:00
start :: [String] -> CommandStart
start ps = go =<< currentView
where
go Nothing = error "Not in a view."
go (Just v) = do
2014-02-19 01:57:21 +00:00
showStart "vpop" (show num)
2014-02-19 01:02:27 +00:00
removeView v
2014-02-19 02:12:42 +00:00
(oldvs, vs) <- splitAt (num - 1) . filter (sameparentbranch v)
2014-02-19 01:57:21 +00:00
<$> recentViews
2014-02-19 02:12:42 +00:00
mapM_ removeView oldvs
case vs of
2014-02-19 01:02:27 +00:00
(oldv:_) -> next $ next $ do
2014-02-19 01:57:21 +00:00
showOutput
checkoutViewBranch oldv (return . branchView)
2014-02-19 01:57:21 +00:00
_ -> next $ next $ do
showOutput
inRepo $ Git.Command.runBool
[ Param "checkout"
, Param $ Git.fromRef $ Git.Ref.base $
viewParentBranch v
]
sameparentbranch a b = viewParentBranch a == viewParentBranch b
2014-02-19 01:57:21 +00:00
num = fromMaybe 1 $ readish =<< headMaybe ps