Skip to content

Commit

Permalink
Merge branch 'kmicklas-force-update-thunk' into develop
Browse files Browse the repository at this point in the history
* kmicklas-force-update-thunk:
  Add changelog for forced-packing of thunks; update warning message
  Add option to force pack thunks
  • Loading branch information
ali-abrar committed May 18, 2019
2 parents 62a192d + b1e4c40 commit 1f9f466
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This project's release branch is `master`. This log is written from the perspect
* Allow skeleton's obelisk to be overridden. This changes the skeleton's default.nix interface: the arguments that it used to take are now part of the new "obelisk" argument.
* Removed `MonadIO` from `ObeliskWidget` to prevent accidental IO during prerendering. If you need to do IO in a widget it should be on the right hand side of a `prerender`.
* Significantly changed the interface to the "executable config" packages. `obelisk-executable-config-lookup` is a new internal package which looks up all configs in a platform-specific way. `obelisk-executable-frontend` and `obelisk-executable-backend` provide MTL-style monad classes (`HasFrontendConfigs` and `HasBackendConfigs`) which the frontend and backend, respectively, can use to look up configs. This replaces the old `get` function which ran in `IO`.
* Add a flag to force thunk packing even if there are unpushed changes in the unpacked thunk.


## v0.1.0.0 - 2019-03-29

Expand Down
11 changes: 7 additions & 4 deletions lib/command/src/Obelisk/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,17 @@ thunkDirectoryParser = fmap (dropTrailingPathSeparator . normalise) . strArgumen
data ThunkCommand
= ThunkCommand_Update [FilePath] (Maybe String)
| ThunkCommand_Unpack [FilePath]
| ThunkCommand_Pack [FilePath]
| ThunkCommand_Pack [FilePath] Bool
deriving Show

forceFlag :: Parser Bool
forceFlag = switch $ long "force" <> short 'f' <> help "Force packing thunks even if there are branches not pushed upstream, uncommitted changes, stashes. This will cause changes that have not been pushed upstream to be lost; use with care."

thunkCommand :: Parser ThunkCommand
thunkCommand = hsubparser $ mconcat
[ command "update" $ info (ThunkCommand_Update <$> some thunkDirectoryParser <*> optional (strOption (long "branch" <> metavar "BRANCH"))) $ progDesc "Update thunk to latest revision available"
, command "unpack" $ info (ThunkCommand_Unpack <$> some thunkDirectoryParser) $ progDesc "Unpack thunk into git checkout of revision it points to"
, command "pack" $ info (ThunkCommand_Pack <$> some thunkDirectoryParser) $ progDesc "Pack git checkout into thunk that points at the current branch's upstream"
, command "pack" $ info (ThunkCommand_Pack <$> some thunkDirectoryParser <*> forceFlag) $ progDesc "Pack git checkout into thunk that points at the current branch's upstream"
]

data ShellOpts
Expand Down Expand Up @@ -342,7 +345,7 @@ ob = \case
Right (ThunkData_Packed ptr) -> return ptr
Right (ThunkData_Checkout (Just ptr)) -> return ptr
Right (ThunkData_Checkout Nothing) ->
getThunkPtr' False root
getThunkPtr False root
let sshKeyPath = _deployInitOpts_sshKey deployOpts
hostname = _deployInitOpts_hostname deployOpts
route = _deployInitOpts_route deployOpts
Expand All @@ -361,7 +364,7 @@ ob = \case
ObCommand_Thunk tc -> case tc of
ThunkCommand_Update thunks mBranch -> mapM_ ((flip updateThunkToLatest) mBranch) thunks
ThunkCommand_Unpack thunks -> mapM_ unpackThunk thunks
ThunkCommand_Pack thunks -> forM_ thunks packThunk
ThunkCommand_Pack thunks force -> forM_ thunks (packThunk force)
ObCommand_Repl -> runRepl
ObCommand_Watch -> inNixShell' $ static runWatch
ObCommand_Shell so -> withProjectRoot "." $ \root ->
Expand Down
2 changes: 1 addition & 1 deletion lib/command/src/Obelisk/Command/Deploy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ deployPush deployPath getNixBuilders = do
Right (ThunkData_Packed ptr) -> return ptr
Right (ThunkData_Checkout _) -> do
checkGitCleanStatus srcPath True >>= \case
True -> packThunk srcPath
True -> packThunk False srcPath
False -> failWith $ T.pack $ "ob deploy push: ensure " <> srcPath <> " has no pending changes and latest is pushed upstream."
Left err -> failWith $ "ob deploy push: couldn't read src thunk: " <> T.pack (show err)
let version = show . _thunkRev_commit $ _thunkPtr_rev thunkPtr
Expand Down
19 changes: 7 additions & 12 deletions lib/command/src/Obelisk/Command/Thunk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Obelisk.Command.Thunk
, readThunk
, updateThunk
, getThunkPtr
, getThunkPtr'
, parseGitUri
, uriThunkPtr
) where
Expand Down Expand Up @@ -573,7 +572,7 @@ updateThunk p f = withSystemTempDirectory "obelisk-thunkptr-" $ \tmpDir -> do
return tmpThunk
Right _ -> failWith $ "Thunk is not packed"
updateThunkFromTmp p' = do
_ <- packThunk' True p'
_ <- packThunk' True False p'
callProcessAndLogOutput (Notice, Error) $
proc "cp" ["-r", "-T", p', p]

Expand Down Expand Up @@ -622,28 +621,24 @@ unpackThunk' noTrail thunkDir = checkThunkDirectory "Can't pack/unpack from with
callProcessAndLogOutput (Notice, Error) $
proc "mv" ["-T", tmpRepo, thunkDir]

--TODO: add force mode to pack even if changes are present
--TODO: add a rollback mode to pack to the original thunk
packThunk :: MonadObelisk m => FilePath -> m ThunkPtr
packThunk :: MonadObelisk m => Bool -> FilePath -> m ThunkPtr
packThunk = packThunk' False

packThunk' :: MonadObelisk m => Bool -> FilePath -> m ThunkPtr
packThunk' noTrail thunkDir = checkThunkDirectory "Can't pack/unpack from within the thunk directory" thunkDir >> readThunk thunkDir >>= \case
packThunk' :: MonadObelisk m => Bool -> Bool -> FilePath -> m ThunkPtr
packThunk' noTrail force thunkDir = checkThunkDirectory "Can't pack/unpack from within the thunk directory" thunkDir >> readThunk thunkDir >>= \case
Left err -> failWith $ T.pack $ "thunk pack: " <> show err
Right (ThunkData_Packed _) -> failWith "pack: thunk is already packed"
Right (ThunkData_Checkout _) -> do
withSpinner' ("Packing thunk " <> T.pack thunkDir)
(finalMsg noTrail $ const $ "Packed thunk " <> T.pack thunkDir) $ do
thunkPtr <- getThunkPtr thunkDir
thunkPtr <- getThunkPtr (not force) thunkDir
callProcessAndLogOutput (Debug, Error) $ proc "rm" ["-rf", thunkDir]
liftIO $ createThunk thunkDir thunkPtr
pure thunkPtr

getThunkPtr :: MonadObelisk m => FilePath -> m ThunkPtr
getThunkPtr = getThunkPtr' True

getThunkPtr' :: forall m. MonadObelisk m => Bool -> FilePath -> m ThunkPtr
getThunkPtr' checkClean thunkDir = do
getThunkPtr :: forall m. MonadObelisk m => Bool -> FilePath -> m ThunkPtr
getThunkPtr checkClean thunkDir = do
when checkClean $ ensureCleanGitRepo thunkDir True $
"thunk pack: thunk checkout contains unsaved modifications"

Expand Down

0 comments on commit 1f9f466

Please sign in to comment.