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
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-02-18 21:38:23 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.VPop where
|
|
|
|
|
|
|
|
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
|
2019-08-26 19:52:19 +00:00
|
|
|
cmd = notBareRepo $
|
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
|
2018-10-01 18:12:06 +00:00
|
|
|
seek = withWords (commandAction . 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
|
2016-11-16 01:29:54 +00:00
|
|
|
go Nothing = giveup "Not in a view."
|
2023-02-27 18:39:33 +00:00
|
|
|
go (Just (v, madj)) = starting "vpop" ai si $ do
|
2024-11-11 18:15:51 +00:00
|
|
|
(oldvs, vs) <- splitAt (num - 1)
|
|
|
|
. filter (sameparentbranch v)
|
|
|
|
. filter (/= v)
|
2014-02-19 01:57:21 +00:00
|
|
|
<$> recentViews
|
2024-11-11 18:15:51 +00:00
|
|
|
let removeview = mapM_ removeView (v : oldvs)
|
|
|
|
ok <- case vs of
|
|
|
|
(oldv:_) -> do
|
2014-02-19 01:57:21 +00:00
|
|
|
showOutput
|
2023-02-27 18:39:33 +00:00
|
|
|
checkoutViewBranch oldv madj
|
|
|
|
(\v' madj' -> return (branchView v' madj'))
|
2024-11-11 18:15:51 +00:00
|
|
|
_ -> do
|
2014-02-19 01:57:21 +00:00
|
|
|
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
|
|
|
|
]
|
2024-11-11 18:15:51 +00:00
|
|
|
if ok
|
|
|
|
then
|
|
|
|
next $ do
|
|
|
|
removeview
|
|
|
|
return True
|
|
|
|
else next $ return False
|
2014-02-18 21:38:23 +00:00
|
|
|
sameparentbranch a b = viewParentBranch a == viewParentBranch b
|
2014-02-19 01:57:21 +00:00
|
|
|
|
|
|
|
num = fromMaybe 1 $ readish =<< headMaybe ps
|
2020-09-14 20:49:33 +00:00
|
|
|
|
2023-04-08 19:48:32 +00:00
|
|
|
ai = ActionItemOther (Just $ UnquotedString $ show num)
|
2020-09-14 20:49:33 +00:00
|
|
|
|
|
|
|
si = SeekInput ps
|