git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1319 from hdgarrood/publish-ensure-clean-tree

Check for a clean working tree in psc-publish

commitbeb86e9d5cc0b190ab681012d6111c28447dd7d7 authorPhil Freeman <paf31@cantab.net> dateSat 1 Aug 2015, 18:50 (11 years ago) parentd96b0efeb3f440
2 files changed+26
src/Language/PureScript/Publish.hs+20 src/Language/PureScript/Publish/ErrorsWarnings.hs+6
src/Language/PureScript/Publish.hs+20
@@ -10,6 +10,8 @@ module Language.PureScript.Publish
1010 , runPrepareM
1111 , PublishOptions(..)
1212 , defaultPublishOptions
13+ , getGitWorkingTreeStatus
14+ , requireCleanWorkingTree
1315 , getVersionFromGitTag
1416 , getBowerInfo
1517 , getModulesAndBookmarks
@@ -112,6 +114,8 @@ preparePackage' opts = do
112114 exists <- liftIO (doesFileExist "bower.json")
113115 unless exists (userError BowerJSONNotFound)
114116
117+ requireCleanWorkingTree
118+
115119 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
116120 >>= flip catchLeft (userError . CouldntParseBowerJSON)
117121 (pkgVersionTag, pkgVersion) <- publishGetVersion opts
@@ -136,6 +140,22 @@ getModulesAndBookmarks = do
136140 renderModules bookmarks modules =
137141 return (bookmarks, map D.convertModule modules)
138142
143+data TreeStatus = Clean | Dirty deriving (Show, Eq, Ord, Enum)
144+
145+getGitWorkingTreeStatus :: PrepareM TreeStatus
146+getGitWorkingTreeStatus = do
147+ out <- readProcess' "git" ["status", "--porcelain"] ""
148+ return $
149+ if null . filter (not . null) . lines $ out
150+ then Clean
151+ else Dirty
152+
153+requireCleanWorkingTree :: PrepareM ()
154+requireCleanWorkingTree = do
155+ status <- getGitWorkingTreeStatus
156+ unless (status == Clean) $
157+ userError DirtyWorkingTree
158+
139159getVersionFromGitTag :: PrepareM (String, Version)
140160getVersionFromGitTag = do
141161 out <- readProcess' "git" ["tag", "--list", "--points-at", "HEAD"] ""
src/Language/PureScript/Publish/ErrorsWarnings.hs+6
@@ -60,6 +60,7 @@ data UserError
6060 | BadRepositoryField RepositoryFieldError
6161 | MissingDependencies (NonEmpty PackageName)
6262 | ParseAndDesugarError D.ParseDesugarError
63+ | DirtyWorkingTree
6364 deriving (Show)
6465
6566data RepositoryFieldError
@@ -196,6 +197,11 @@ displayUserError e = case e of
196197 [ para "Error while desugaring:"
197198 , indented (para (P.prettyPrintMultipleErrors False err))
198199 ]
200+ DirtyWorkingTree ->
201+ para (concat
202+ [ "Your git working tree is dirty. Please commit, discard, or stash "
203+ , "your changes first."
204+ ])
199205
200206displayRepositoryError :: RepositoryFieldError -> Box
201207displayRepositoryError err = case err of