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.View where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Git
|
|
|
|
import qualified Git.Command
|
|
|
|
import qualified Git.Ref
|
|
|
|
import qualified Git.Branch
|
|
|
|
import Types.View
|
|
|
|
import Annex.View
|
|
|
|
import Logs.View
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
|
|
|
cmd = notBareRepo $ notDirect $
|
2015-07-08 19:08:02 +00:00
|
|
|
command "view" SectionMetaData "enter a view branch"
|
|
|
|
paramView (withParams seek)
|
2014-02-18 21:38:23 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2014-02-18 21:38:23 +00:00
|
|
|
seek = withWords start
|
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
2016-11-16 01:29:54 +00:00
|
|
|
start [] = giveup "Specify metadata to include in view"
|
2015-07-08 19:08:02 +00:00
|
|
|
start ps = do
|
2014-02-18 21:38:23 +00:00
|
|
|
showStart "view" ""
|
2015-07-08 19:08:02 +00:00
|
|
|
view <- mkView ps
|
2014-02-18 21:38:23 +00:00
|
|
|
go view =<< currentView
|
|
|
|
where
|
|
|
|
go view Nothing = next $ perform view
|
|
|
|
go view (Just v)
|
|
|
|
| v == view = stop
|
2016-11-16 01:29:54 +00:00
|
|
|
| otherwise = giveup "Already in a view. Use the vfilter and vadd commands to further refine this view."
|
2014-02-18 21:38:23 +00:00
|
|
|
|
|
|
|
perform :: View -> CommandPerform
|
|
|
|
perform view = do
|
2015-10-11 17:29:44 +00:00
|
|
|
showAction "searching"
|
2014-02-19 00:57:14 +00:00
|
|
|
next $ checkoutViewBranch view applyView
|
2014-02-18 21:38:23 +00:00
|
|
|
|
|
|
|
paramView :: String
|
2014-10-21 17:00:05 +00:00
|
|
|
paramView = paramRepeating "FIELD=VALUE"
|
2014-02-18 21:38:23 +00:00
|
|
|
|
|
|
|
mkView :: [String] -> Annex View
|
2015-07-08 19:08:02 +00:00
|
|
|
mkView ps = go =<< inRepo Git.Branch.current
|
2014-02-18 21:38:23 +00:00
|
|
|
where
|
2016-11-16 01:29:54 +00:00
|
|
|
go Nothing = giveup "not on any branch!"
|
2014-03-02 20:00:56 +00:00
|
|
|
go (Just b) = return $ fst $ refineView (View b []) $
|
2015-07-08 19:08:02 +00:00
|
|
|
map parseViewParam $ reverse ps
|
2014-02-18 21:38:23 +00:00
|
|
|
|
2014-02-19 00:57:14 +00:00
|
|
|
checkoutViewBranch :: View -> (View -> Annex Git.Branch) -> CommandCleanup
|
|
|
|
checkoutViewBranch view mkbranch = do
|
2015-01-07 01:01:05 +00:00
|
|
|
here <- liftIO getCurrentDirectory
|
2014-02-19 00:57:14 +00:00
|
|
|
|
|
|
|
branch <- mkbranch view
|
|
|
|
|
2014-02-19 01:57:21 +00:00
|
|
|
showOutput
|
2014-02-18 21:38:23 +00:00
|
|
|
ok <- inRepo $ Git.Command.runBool
|
|
|
|
[ Param "checkout"
|
2014-02-19 05:09:17 +00:00
|
|
|
, Param (Git.fromRef $ Git.Ref.base branch)
|
2014-02-18 21:38:23 +00:00
|
|
|
]
|
|
|
|
when ok $ do
|
|
|
|
setView view
|
|
|
|
{- A git repo can easily have empty directories in it,
|
|
|
|
- and this pollutes the view, so remove them. -}
|
2015-01-07 01:01:05 +00:00
|
|
|
top <- fromRepo Git.repoPath
|
|
|
|
liftIO $ removeemptydirs top
|
|
|
|
unlessM (liftIO $ doesDirectoryExist here) $ do
|
2014-02-18 21:38:23 +00:00
|
|
|
showLongNote (cwdmissing top)
|
|
|
|
return ok
|
|
|
|
where
|
|
|
|
removeemptydirs top = mapM_ (tryIO . removeDirectory)
|
|
|
|
=<< dirTreeRecursiveSkipping (".git" `isSuffixOf`) top
|
|
|
|
cwdmissing top = unlines
|
|
|
|
[ "This view does not include the subdirectory you are currently in."
|
|
|
|
, "Perhaps you should: cd " ++ top
|
|
|
|
]
|