@@ -378,20 +378,38 @@ createThunkWithLatest target s = do
378378 , _thunkPtr_rev = rev
379379 }
380380
381−updateThunkToLatest :: MonadObelisk m => FilePath -> m ()
382−updateThunkToLatest target = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest") $ do
381+updateThunkToLatest :: MonadObelisk m => FilePath -> Maybe String -> m ()
382+updateThunkToLatest target mBranch = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest") $ do
383383 checkThunkDirectory "ob thunk update directory cannot be '.'" target
384− (overwrite, ptr) <- readThunk target >>= \case
385− Left err -> failWith $ T.pack $ "thunk update: " <> show err
386− Right c -> case c of
387− ThunkData_Packed t -> return (target, t)
388− ThunkData_Checkout _ -> failWith "cannot update an unpacked thunk"
389− let src = _thunkPtr_source ptr
390− rev <- getLatestRev src
391− overwriteThunk overwrite $ ThunkPtr
392− { _thunkPtr_source = src
393− , _thunkPtr_rev = rev
394− }
384+ -- check to see if thunk should be updated to a specific branch or just update it's current branch
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 -> readThunk target >>= \case
399+ Left err -> failWith $ T.pack $ "thunk update: " <> show err
400+ Right c -> case c of
401+ ThunkData_Packed t -> case _thunkPtr_source t of
402+ ThunkSource_Git tsg -> setThunk target tsg branch
403+ ThunkSource_GitHub tsgh -> do
404+ let tsg = forgetGithub False tsgh
405+ setThunk target tsg branch
406+ ThunkData_Checkout _ -> failWith $ T.pack $ "thunk located at " <> (show target) <> " is unpacked. Use ob thunk pack on the desired directory and then try ob thunk update again."
407+
408+setThunk :: MonadObelisk m => FilePath -> GitSource -> String -> m ()
409+setThunk target gs branch = do
410+ newThunkPtr <- uriThunkPtr (_gitSource_url gs) (Just $ T.pack branch) Nothing
411+ overwriteThunk target newThunkPtr
412+ updateThunkToLatest target Nothing
395413
396414-- | All recognized github standalone loaders, ordered from newest to oldest.
397415-- This tool will only ever produce the newest one when it writes a thunk.
@@ -878,9 +896,10 @@ gitThunkRev s commit = do
878896gitGetCommitBranch
879897 :: MonadObelisk m => URI -> Maybe Text -> m (Text, CommitId)
880898gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote " <> uriMsg) $ do
881− bothMaps <- gitLsRemote
899+ (_, bothMaps) <- gitLsRemote
882900 (T.unpack $ render uri)
883901 (GitRef_Branch <$> mbranch)
902+ Nothing
884903 branch <- case mbranch of
885904 Nothing -> withExitFailMessage "Failed to find default branch" $ do
886905 b <- rethrowE $ gitLookupDefaultBranch bothMaps