2014-02-18 17:38:23 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 12:50:09 -04:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-02-18 17:38:23 -04:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.VPop where
|
|
|
|
|
|
|
|
import Command
|
2014-02-19 01:09:17 -04:00
|
|
|
import qualified Git
|
2014-02-18 17:38:23 -04:00
|
|
|
import qualified Git.Command
|
|
|
|
import qualified Git.Ref
|
|
|
|
import Types.View
|
|
|
|
import Logs.View
|
|
|
|
import Command.View (checkoutViewBranch)
|
|
|
|
|
2015-07-08 12:33:27 -04:00
|
|
|
cmd :: Command
|
|
|
|
cmd = notBareRepo $ notDirect $
|
2015-07-08 15:08:02 -04:00
|
|
|
command "vpop" SectionMetaData "switch back to previous view"
|
|
|
|
paramNumber (withParams seek)
|
2014-02-18 17:38:23 -04:00
|
|
|
|
2015-07-08 15:08:02 -04:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2014-02-18 21:57:21 -04:00
|
|
|
seek = withWords start
|
2014-02-18 17:38:23 -04:00
|
|
|
|
2014-02-18 21:57:21 -04:00
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start ps = go =<< currentView
|
2014-02-18 17:38:23 -04:00
|
|
|
where
|
2016-11-15 21:29:54 -04:00
|
|
|
go Nothing = giveup "Not in a view."
|
2014-02-18 17:38:23 -04:00
|
|
|
go (Just v) = do
|
2014-02-18 21:57:21 -04:00
|
|
|
showStart "vpop" (show num)
|
2014-02-18 21:02:27 -04:00
|
|
|
removeView v
|
2014-02-18 22:12:42 -04:00
|
|
|
(oldvs, vs) <- splitAt (num - 1) . filter (sameparentbranch v)
|
2014-02-18 21:57:21 -04:00
|
|
|
<$> recentViews
|
2014-02-18 22:12:42 -04:00
|
|
|
mapM_ removeView oldvs
|
2014-02-18 17:38:23 -04:00
|
|
|
case vs of
|
2014-02-18 21:02:27 -04:00
|
|
|
(oldv:_) -> next $ next $ do
|
2014-02-18 21:57:21 -04:00
|
|
|
showOutput
|
2014-02-18 20:57:14 -04:00
|
|
|
checkoutViewBranch oldv (return . branchView)
|
2014-02-18 21:57:21 -04:00
|
|
|
_ -> next $ next $ do
|
|
|
|
showOutput
|
2014-02-18 17:38:23 -04:00
|
|
|
inRepo $ Git.Command.runBool
|
|
|
|
[ Param "checkout"
|
2014-02-19 01:09:17 -04:00
|
|
|
, Param $ Git.fromRef $ Git.Ref.base $
|
2014-02-18 17:38:23 -04:00
|
|
|
viewParentBranch v
|
|
|
|
]
|
|
|
|
sameparentbranch a b = viewParentBranch a == viewParentBranch b
|
2014-02-18 21:57:21 -04:00
|
|
|
|
|
|
|
num = fromMaybe 1 $ readish =<< headMaybe ps
|