@@ -29,7 +29,6 @@ module Obelisk.Command.Thunk
2929 , getThunkPtr'
3030 , parseGitUri
3131 , uriThunkPtr
32− , setThunk
3332 ) where
3433
3534import Control.Applicative
@@ -395,7 +394,20 @@ updateThunkToLatest target mBranch = withSpinner' ("Updating thunk " <> T.pack t
395394 { _thunkPtr_source = src
396395 , _thunkPtr_rev = rev
397396 }
398− Just branch -> setThunk branch target
397+ Just branch -> readThunk target >>= \case
398+ Left err -> failWith $ T.pack $ "thunk update: " <> show err
399+ Right c -> case c of
400+ ThunkData_Packed t -> case _thunkPtr_source t of
401+ ThunkSource_Git tsg -> do
402+ newThunkPtr <- uriThunkPtr (_gitSource_url tsg) $ Just $ T.pack branch
403+ overwriteThunk target newThunkPtr
404+ updateThunkToLatest target Nothing
405+ ThunkSource_GitHub tsgh -> do
406+ let tsg = forgetGithub False tsgh
407+ newThunkPtr <- uriThunkPtr (_gitSource_url tsg) $ Just $ T.pack branch
408+ overwriteThunk target newThunkPtr
409+ updateThunkToLatest target Nothing
410+ 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."
399411
400412-- | All recognized github standalone loaders, ordered from newest to oldest.
401413-- This tool will only ever produce the newest one when it writes a thunk.
@@ -626,47 +638,6 @@ packThunk' noTrail thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir
626638 liftIO $ createThunk thunkDir thunkPtr
627639 pure thunkPtr
628640
629−-- set thunk to a desired branch
630−setThunk :: MonadObelisk m => String -> FilePath -> m ()
631−setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
632− Left err -> failWith $ T.pack $ "thunk set : " <> show err
633− Right (ThunkData_Packed thunkptr) -> do
634− let thunkSrc = _thunkPtr_source thunkptr
635− repository = case thunkSrc of
636− ThunkSource_Git gitSource -> T.unpack $ render $ _gitSource_url gitSource
637− ThunkSource_GitHub gitHubSource -> T.unpack $ render $ _gitSource_url $ forgetGithub True gitHubSource
638− -- check to see if branch exists before modifying directory
639− (exitCode, _) <- gitLsRemoteExitCode repository branch
640− case exitCode of
641− ExitSuccess -> do
642− remoteResults <- readGitProcessNoRepo ["ls-remote", repository, branch]
643− uri <- mkURI $ T.pack repository
644− let rev = head $ T.words remoteResults -- TODO: Don't use head
645− sha256 <- nixPrefetchGit uri rev False
646− let newThunkPtr = ThunkPtr
647− { _thunkPtr_source = case _thunkPtr_source thunkptr of
648− ThunkSource_Git gitSource -> ThunkSource_Git GitSource
649− { _gitSource_url = _gitSource_url gitSource
650− , _gitSource_branch = Just $ N $ T.pack branch
651− , _gitSource_fetchSubmodules = _gitSource_fetchSubmodules gitSource
652− }
653− ThunkSource_GitHub gitHubSource -> ThunkSource_GitHub GitHubSource
654− { _gitHubSource_owner = _gitHubSource_owner gitHubSource
655− , _gitHubSource_repo = _gitHubSource_repo gitHubSource
656− , _gitHubSource_branch = Just $ N $ T.pack branch
657− }
658− , _thunkPtr_rev = ThunkRev
659− { _thunkRev_commit = Ref.hash $ encodeUtf8 rev
660− , _thunkRev_nixSha256 = sha256
661− }
662− }
663− overwriteThunk thunkDir newThunkPtr
664− updateThunkToLatest thunkDir Nothing
665− ExitFailure errNum -> failWith $ T.pack $ if errNum == 2
666− then "Error: branch not found"
667− else ("Error Code: " <> show errNum <> "issue checking out the desired branch")
668− Right (ThunkData_Checkout _) -> failWith $ T.pack $ "thunk located at " <> (show thunkDir) <> " is unpacked. Use ob thunk pack on the desired directory and then try ob thunk set again."
669−
670641getThunkPtr :: MonadObelisk m => FilePath -> m ThunkPtr
671642getThunkPtr = getThunkPtr' True
672643