summaryrefslogtreecommitdiff
path: root/Command/VPop.hs
blob: e62c2414af265384a8e86df87834a46c64d1c5e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{- 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
import qualified Git.Command
import qualified Git.Ref
import Types.View
import Logs.View
import Command.View (checkoutViewBranch)

def :: [Command]
def = [notBareRepo $ notDirect $
	command "vpop" paramNothing seek SectionUtility
	"switch back to previous view"]

seek :: CommandSeek
seek = withNothing start

start ::CommandStart
start = go =<< currentView
  where
	go Nothing = error "Not in a view."
	go (Just v) = do
		showStart "vpop" ""
		removeView v
		vs <- filter (sameparentbranch v) <$> recentViews
		case vs of
			(oldv:_) -> next $ next $ do
				checkoutViewBranch oldv (return . branchView)
			_ -> next $ next $
				inRepo $ Git.Command.runBool
					[ Param "checkout"
					, Param $ show $ Git.Ref.base $
						viewParentBranch v
					]
	sameparentbranch a b = viewParentBranch a == viewParentBranch b