2014-02-18 21:38:23 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2014 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- 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)
|
|
|
|
|
|
|
|
def :: [Command]
|
|
|
|
def = [notBareRepo $ notDirect $
|
2014-02-19 01:57:21 +00:00
|
|
|
command "vpop" (paramOptional paramNumber) seek SectionUtility
|
2014-02-18 21:38:23 +00:00
|
|
|
"switch back to previous view"]
|
|
|
|
|
|
|
|
seek :: 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
|