on master help sign in
ob deploy init: Improve error messages

* when project root is not a git repository or an invalid thunk. * when deploy dir is the same as project root

commitd81cea01ba4634ba896b72e5f60ca7afd6191270 authorLuigy Leon <luigy@outlook.com> dateWed 16 May 2018, 08:39 (8 years ago) parent733880e
2 files changed+12−3
lib/command/src/Obelisk/Command.hs+11−3 lib/command/src/Obelisk/Command/Thunk.hs+1
lib/command/src/Obelisk/Command.hs+11−3
@@ -22,6 +22,7 @@ import qualified Data.Text as T
2222import Data.Text.Encoding
2323import GHC.StaticPtr
2424import Options.Applicative
25+import System.Directory
2526import System.Environment
2627import System.FilePath
2728import System.IO (hIsTerminalDevice, stdout)
@@ -263,14 +264,21 @@ ob = \case
263264 ObCommand_Init source -> initProject source
264265 ObCommand_Deploy dc -> case dc of
265266 DeployCommand_Init deployOpts -> withProjectRoot "." $ \root -> do
267+ let deployDir = _deployInitOpts_ouputDir deployOpts
268+ r <- liftIO $ canonicalizePath root
269+ rootEqualsTarget <- liftIO $ equalFilePath r <$> canonicalizePath deployDir
270+ when rootEqualsTarget $
271+ failWith $ "Deploy directory " <> T.pack deployDir <> " should not be the same as project root."
266272 thunkPtr <- readThunk root >>= \case
267− Left err -> failWith $ T.pack $ "thunk pack: " <> show err
273+ Left err -> failWith $ case err of
274+ ReadThunkError_WrongContents _ _ ->
275+ "Project root " <> T.pack r <> " is not a git repository or valid thunk"
276+ _ -> "thunk read: " <> T.pack (show err)
268277 Right (ThunkData_Packed ptr) -> return ptr
269278 Right (ThunkData_Checkout (Just ptr)) -> return ptr
270279 Right (ThunkData_Checkout Nothing) ->
271280 getThunkPtr root (_deployInitOpts_remote deployOpts)
272− let deployDir = _deployInitOpts_ouputDir deployOpts
273− sshKeyPath = _deployInitOpts_sshKey deployOpts
281+ let sshKeyPath = _deployInitOpts_sshKey deployOpts
274282 hostname = _deployInitOpts_hostname deployOpts
275283 deployInit thunkPtr (root </> "config") deployDir sshKeyPath hostname
276284 DeployCommand_Push -> deployPush "."
lib/command/src/Obelisk/Command/Thunk.hs+1
@@ -12,6 +12,7 @@ module Obelisk.Command.Thunk
1212 , ThunkRev (..)
1313 , ThunkSource (..)
1414 , ThunkData (..)
15+ , ReadThunkError (..)
1516 , GitHubSource (..)
1617 , getLatestRev
1718 , updateThunkToLatest