summaryrefslogtreecommitdiff
path: root/Command/Status.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-18 12:05:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-18 12:05:10 -0400
commita46e72101af416254a29c23471e003b17d4de8e2 (patch)
tree90164d0940fbefb3073956c26196a55658742e05 /Command/Status.hs
parent196dacb6758b2284448cb2f9e1ba6e0e67a46534 (diff)
status: Support --json.
Diffstat (limited to 'Command/Status.hs')
-rw-r--r--Command/Status.hs18
1 files changed, 11 insertions, 7 deletions
diff --git a/Command/Status.hs b/Command/Status.hs
index 5dc625994..27127b3ec 100644
--- a/Command/Status.hs
+++ b/Command/Status.hs
@@ -15,9 +15,10 @@ import Config
import qualified Git.LsFiles as LsFiles
import qualified Git.Ref
import qualified Git
+import GitAnnex.Options
def :: [Command]
-def = [notBareRepo $ noCommit $ noMessages $
+def = [notBareRepo $ noCommit $ noMessages $ withOptions [jsonOption] $
command "status" paramPaths seek SectionCommon
"show the working tree status"]
@@ -32,11 +33,11 @@ start [] = do
-- given the path to the top of the repository.
cwd <- liftIO getCurrentDirectory
top <- fromRepo Git.repoPath
- next $ perform [relPathDirToFile cwd top]
-start locs = next $ perform locs
+ start' [relPathDirToFile cwd top]
+start locs = start' locs
-perform :: [FilePath] -> CommandPerform
-perform locs = do
+start' :: [FilePath] -> CommandStart
+start' locs = do
(l, cleanup) <- inRepo $ LsFiles.modifiedOthers locs
getstatus <- ifM isDirect
( return statusDirect
@@ -44,7 +45,7 @@ perform locs = do
)
forM_ l $ \f -> maybe noop (showFileStatus f) =<< getstatus f
void $ liftIO cleanup
- next $ return True
+ stop
data Status
= NewFile
@@ -57,7 +58,10 @@ showStatus DeletedFile = "D"
showStatus ModifiedFile = "M"
showFileStatus :: FilePath -> Status -> Annex ()
-showFileStatus f s = liftIO $ putStrLn $ showStatus s ++ " " ++ f
+showFileStatus f s = unlessM (showFullJSON [("status", ss), ("file", f)]) $
+ liftIO $ putStrLn $ ss ++ " " ++ f
+ where
+ ss = showStatus s
statusDirect :: FilePath -> Annex (Maybe Status)
statusDirect f = checkstatus =<< liftIO (catchMaybeIO $ getFileStatus f)