2014-02-18 21:38:23 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-02-18 21:38:23 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.VPop where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Command
|
2014-02-19 05:09:17 +00:00
|
|
|
import qualified Git
|
2014-02-18 21:38:23 +00:00
|
|
|
import qualified Git.Command
|
|
|
|
import qualified Git.Ref
|
|
|
|
import Types.View
|
|
|
|
import Logs.View
|
|
|
|
import Command.View (checkoutViewBranch)
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = notBareRepo $ notDirect $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "vpop" SectionMetaData "switch back to previous view"
|
|
|
|
paramNumber (withParams seek)
|
2014-02-18 21:38:23 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2014-02-19 01:57:21 +00:00
|
|
|
seek = withWords start
|
2014-02-18 21:38:23 +00:00
|
|
|
|
2014-02-19 01:57:21 +00:00
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start ps = go =<< currentView
|
2014-02-18 21:38:23 +00:00
|
|
|
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
|
2014-02-18 21:38:23 +00:00
|
|
|
case vs of
|
2014-02-19 01:02:27 +00:00
|
|
|
(oldv:_) -> next $ next $ do
|
2014-02-19 01:57:21 +00:00
|
|
|
showOutput
|
2014-02-19 00:57:14 +00:00
|
|
|
checkoutViewBranch oldv (return . branchView)
|
2014-02-19 01:57:21 +00:00
|
|
|
_ -> next $ next $ do
|
|
|
|
showOutput
|
2014-02-18 21:38:23 +00:00
|
|
|
inRepo $ Git.Command.runBool
|
|
|
|
[ Param "checkout"
|
2014-02-19 05:09:17 +00:00
|
|
|
, Param $ Git.fromRef $ Git.Ref.base $
|
2014-02-18 21:38:23 +00:00
|
|
|
viewParentBranch v
|
|
|
|
]
|
|
|
|
sameparentbranch a b = viewParentBranch a == viewParentBranch b
|
2014-02-19 01:57:21 +00:00
|
|
|
|
|
|
|
num = fromMaybe 1 $ readish =<< headMaybe ps
|