on master help sign in
change syntax to 'ob thunk update --branch some-branch'
commit63c7b21d13b0b7122051dc26b15b3c18c6cd3f46 authorhsloan <ishaqsloan@gmail.com> dateThu 29 Nov 2018, 20:52 (8 years ago) parent1566ae3
3 files changed+22−17
lib/command/src/Obelisk/Command.hs+3−3 lib/command/src/Obelisk/Command/Deploy.hs+1−1 lib/command/src/Obelisk/Command/Thunk.hs+18−13
lib/command/src/Obelisk/Command.hs+3−3
@@ -211,7 +211,7 @@ thunkDirectoryParser = fmap (dropTrailingPathSeparator . normalise) . strArgumen
211211 ]
212212
213213data ThunkCommand
214− = ThunkCommand_Update [FilePath]
214+ = ThunkCommand_Update [FilePath] (Maybe String)
215215 | ThunkCommand_Unpack [FilePath]
216216 | ThunkCommand_Pack [FilePath]
217217 | ThunkCommand_Set [FilePath] String
@@ -219,7 +219,7 @@ data ThunkCommand
219219
220220thunkCommand :: Parser ThunkCommand
221221thunkCommand = hsubparser $ mconcat
222− [ command "update" $ info (ThunkCommand_Update <$> some thunkDirectoryParser) $ progDesc "Update thunk to latest revision available"
222+ [ command "update" $ info (ThunkCommand_Update <$> some thunkDirectoryParser <*> optional (strOption (long "branch" <> metavar "BRANCH"))) $ progDesc "Update thunk to latest revision available"
223223 , command "unpack" $ info (ThunkCommand_Unpack <$> some thunkDirectoryParser) $ progDesc "Unpack thunk into git checkout of revision it points to"
224224 , command "pack" $ info (ThunkCommand_Pack <$> some thunkDirectoryParser) $ progDesc "Pack git checkout into thunk that points at the current branch's upstream"
225225 , command "set" $ info (ThunkCommand_Set <$> some thunkDirectoryParser <*> strOption (long "branch" <> metavar "BRANCH")) $ progDesc "Set upstream branch of thunk"
@@ -348,7 +348,7 @@ ob = \case
348348 ObCommand_Run -> inNixShell' $ static run
349349 -- inNixShell ($(mkClosure 'ghcidAction) ())
350350 ObCommand_Thunk tc -> case tc of
351− ThunkCommand_Update thunks -> mapM_ updateThunkToLatest thunks
351+ ThunkCommand_Update thunks mBranch -> mapM_ ((flip updateThunkToLatest) mBranch) thunks
352352 ThunkCommand_Unpack thunks -> mapM_ unpackThunk thunks
353353 ThunkCommand_Pack thunks -> forM_ thunks packThunk
354354 ThunkCommand_Set thunks branch -> mapM_ (setThunk branch) thunks
lib/command/src/Obelisk/Command/Deploy.hs+1−1
@@ -148,7 +148,7 @@ deployPush deployPath getNixBuilders = do
148148 callProcessAndLogOutput (Notice, Notice) p
149149
150150deployUpdate :: MonadObelisk m => FilePath -> m ()
151−deployUpdate deployPath = updateThunkToLatest $ deployPath </> "src"
151+deployUpdate deployPath = updateThunkToLatest (deployPath </> "src") Nothing
152152
153153deployMobile :: MonadObelisk m => String -> [String] -> m ()
154154deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
lib/command/src/Obelisk/Command/Thunk.hs+18−13
@@ -380,19 +380,22 @@ createThunkWithLatest target s = do
380380 , _thunkPtr_rev = rev
381381 }
382382
383−updateThunkToLatest :: MonadObelisk m => FilePath -> m ()
384−updateThunkToLatest target = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest") $ do
385− (overwrite, ptr) <- readThunk target >>= \case
386− Left err -> failWith $ T.pack $ "thunk update: " <> show err
387− Right c -> case c of
388− ThunkData_Packed t -> return (target, t)
389− ThunkData_Checkout _ -> failWith "cannot update an unpacked thunk"
390− let src = _thunkPtr_source ptr
391− rev <- getLatestRev src
392− overwriteThunk overwrite $ ThunkPtr
393− { _thunkPtr_source = src
394− , _thunkPtr_rev = rev
395− }
383+updateThunkToLatest :: MonadObelisk m => FilePath -> Maybe String -> m ()
384+updateThunkToLatest target mBranch = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest") $
385+ case mBranch of
386+ Nothing -> do
387+ (overwrite, ptr) <- readThunk target >>= \case
388+ Left err -> failWith $ T.pack $ "thunk update: " <> show err
389+ Right c -> case c of
390+ ThunkData_Packed t -> return (target, t)
391+ ThunkData_Checkout _ -> failWith "cannot update an unpacked thunk"
392+ let src = _thunkPtr_source ptr
393+ rev <- getLatestRev src
394+ overwriteThunk overwrite $ ThunkPtr
395+ { _thunkPtr_source = src
396+ , _thunkPtr_rev = rev
397+ }
398+ Just branch -> setThunk branch target
396399
397400-- | All recognized github standalone loaders, ordered from newest to oldest.
398401-- This tool will only ever produce the newest one when it writes a thunk.
@@ -623,6 +626,7 @@ packThunk' noTrail thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir
623626 liftIO $ createThunk thunkDir thunkPtr
624627 pure thunkPtr
625628
629+-- set thunk to a desired branch
626630setThunk :: MonadObelisk m => String -> FilePath -> m ()
627631setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
628632 Left err -> failWith $ T.pack $ "thunk set : " <> show err
@@ -657,6 +661,7 @@ setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>
657661 }
658662 }
659663 overwriteThunk thunkDir newThunkPtr
664+ updateThunkToLatest thunkDir Nothing
660665 ExitFailure errNum -> failWith $ T.pack $ if errNum == 2
661666 then "Error: branch not found"
662667 else ("Error Code: " <> show errNum <> "issue checking out the desired branch")