on master help sign in
change syntax to 'ob thunk update --branch some-branch'
63c7b21hsloan
lib/command/src/Obelisk/Command.hs+3−3
@@ -211,7 +211,7 @@ thunkDirectoryParser = fmap (dropTrailingPathSeparator . normalise) . strArgumen
211 ]
211 ]
212
212
213data ThunkCommand
213data ThunkCommand
214− = ThunkCommand_Update [FilePath]
214+ = ThunkCommand_Update [FilePath] (Maybe String)
215 | ThunkCommand_Unpack [FilePath]
215 | ThunkCommand_Unpack [FilePath]
216 | ThunkCommand_Pack [FilePath]
216 | ThunkCommand_Pack [FilePath]
217 | ThunkCommand_Set [FilePath] String
217 | ThunkCommand_Set [FilePath] String
@@ -219,7 +219,7 @@ data ThunkCommand
219
219
220thunkCommand :: Parser ThunkCommand
220thunkCommand :: Parser ThunkCommand
221thunkCommand = hsubparser $ mconcat
221thunkCommand = 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"
223 , command "unpack" $ info (ThunkCommand_Unpack <$> some thunkDirectoryParser) $ progDesc "Unpack thunk into git checkout of revision it points to"
223 , command "unpack" $ info (ThunkCommand_Unpack <$> some thunkDirectoryParser) $ progDesc "Unpack thunk into git checkout of revision it points to"
224 , command "pack" $ info (ThunkCommand_Pack <$> some thunkDirectoryParser) $ progDesc "Pack git checkout into thunk that points at the current branch's upstream"
224 , command "pack" $ info (ThunkCommand_Pack <$> some thunkDirectoryParser) $ progDesc "Pack git checkout into thunk that points at the current branch's upstream"
225 , command "set" $ info (ThunkCommand_Set <$> some thunkDirectoryParser <*> strOption (long "branch" <> metavar "BRANCH")) $ progDesc "Set upstream branch of thunk"
225 , command "set" $ info (ThunkCommand_Set <$> some thunkDirectoryParser <*> strOption (long "branch" <> metavar "BRANCH")) $ progDesc "Set upstream branch of thunk"
@@ -348,7 +348,7 @@ ob = \case
348 ObCommand_Run -> inNixShell' $ static run
348 ObCommand_Run -> inNixShell' $ static run
349 -- inNixShell ($(mkClosure 'ghcidAction) ())
349 -- inNixShell ($(mkClosure 'ghcidAction) ())
350 ObCommand_Thunk tc -> case tc of
350 ObCommand_Thunk tc -> case tc of
351− ThunkCommand_Update thunks -> mapM_ updateThunkToLatest thunks
351+ ThunkCommand_Update thunks mBranch -> mapM_ ((flip updateThunkToLatest) mBranch) thunks
352 ThunkCommand_Unpack thunks -> mapM_ unpackThunk thunks
352 ThunkCommand_Unpack thunks -> mapM_ unpackThunk thunks
353 ThunkCommand_Pack thunks -> forM_ thunks packThunk
353 ThunkCommand_Pack thunks -> forM_ thunks packThunk
354 ThunkCommand_Set thunks branch -> mapM_ (setThunk branch) thunks
354 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
148 callProcessAndLogOutput (Notice, Notice) p
148 callProcessAndLogOutput (Notice, Notice) p
149
149
150deployUpdate :: MonadObelisk m => FilePath -> m ()
150deployUpdate :: MonadObelisk m => FilePath -> m ()
151−deployUpdate deployPath = updateThunkToLatest $ deployPath </> "src"
151+deployUpdate deployPath = updateThunkToLatest (deployPath </> "src") Nothing
152
152
153deployMobile :: MonadObelisk m => String -> [String] -> m ()
153deployMobile :: MonadObelisk m => String -> [String] -> m ()
154deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
154deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
lib/command/src/Obelisk/Command/Thunk.hs+18−13
@@ -380,19 +380,22 @@ createThunkWithLatest target s = do
380 , _thunkPtr_rev = rev
380 , _thunkPtr_rev = rev
381 }
381 }
382
382
383−updateThunkToLatest :: MonadObelisk m => FilePath -> m ()
383+updateThunkToLatest :: MonadObelisk m => FilePath -> Maybe String -> m ()
384−updateThunkToLatest target = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest") $ do
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
385− (overwrite, ptr) <- readThunk target >>= \case
387+ (overwrite, ptr) <- readThunk target >>= \case
386− Left err -> failWith $ T.pack $ "thunk update: " <> show err
388+ Left err -> failWith $ T.pack $ "thunk update: " <> show err
387− Right c -> case c of
389+ Right c -> case c of
388− ThunkData_Packed t -> return (target, t)
390+ ThunkData_Packed t -> return (target, t)
389− ThunkData_Checkout _ -> failWith "cannot update an unpacked thunk"
391+ ThunkData_Checkout _ -> failWith "cannot update an unpacked thunk"
390− let src = _thunkPtr_source ptr
392+ let src = _thunkPtr_source ptr
391− rev <- getLatestRev src
393+ rev <- getLatestRev src
392− overwriteThunk overwrite $ ThunkPtr
394+ overwriteThunk overwrite $ ThunkPtr
393− { _thunkPtr_source = src
395+ { _thunkPtr_source = src
394− , _thunkPtr_rev = rev
396+ , _thunkPtr_rev = rev
395− }
397+ }
398+ Just branch -> setThunk branch target
396
399
397-- | All recognized github standalone loaders, ordered from newest to oldest.
400-- | All recognized github standalone loaders, ordered from newest to oldest.
398-- This tool will only ever produce the newest one when it writes a thunk.
401-- 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
623 liftIO $ createThunk thunkDir thunkPtr
626 liftIO $ createThunk thunkDir thunkPtr
624 pure thunkPtr
627 pure thunkPtr
625
628
629+-- set thunk to a desired branch
626setThunk :: MonadObelisk m => String -> FilePath -> m ()
630setThunk :: MonadObelisk m => String -> FilePath -> m ()
627setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
631setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
628 Left err -> failWith $ T.pack $ "thunk set : " <> show err
632 Left err -> failWith $ T.pack $ "thunk set : " <> show err
@@ -657,6 +661,7 @@ setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>
657 }
661 }
658 }
662 }
659 overwriteThunk thunkDir newThunkPtr
663 overwriteThunk thunkDir newThunkPtr
664+ updateThunkToLatest thunkDir Nothing
660 ExitFailure errNum -> failWith $ T.pack $ if errNum == 2
665 ExitFailure errNum -> failWith $ T.pack $ if errNum == 2
661 then "Error: branch not found"
666 then "Error: branch not found"
662 else ("Error Code: " <> show errNum <> "issue checking out the desired branch")
667 else ("Error Code: " <> show errNum <> "issue checking out the desired branch")