on master help sign in
handle already unpacked thunks
commit6f77657404c91d1b804c0d49772d21e6a4d6aace authorhsloan <ishaqsloan@gmail.com> dateFri 9 Nov 2018, 22:16 (8 years ago) parent9d2a425
1 file changed+14−9
lib/command/src/Obelisk/Command/Thunk.hs+14−9
lib/command/src/Obelisk/Command/Thunk.hs+14−9
@@ -627,15 +627,20 @@ setThunk :: MonadObelisk m => String -> FilePath -> m ()
627627setThunk = setThunk' False
628628
629629setThunk' :: MonadObelisk m => Bool -> String -> FilePath -> m ()
630−setThunk' noTrail branch thunkDir = do
631− _ <- unpackThunk' noTrail thunkDir
632− -- TODO: may have to get current dir before switching
633− initalDir <- liftIO getCurrentDirectory
634− liftIO $ setCurrentDirectory thunkDir
635− callProcessAndLogOutput (Debug, Error) $ proc "git" ["checkout", branch]
636− liftIO $ setCurrentDirectory initalDir
637− _ <- packThunk' noTrail thunkDir
638− updateThunkToLatest thunkDir
630+setThunk' noTrail branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>= \case
631+ Left err -> failWith $ T.pack $ "thunk set : " <> show err
632+ Right (ThunkData_Packed _) -> do
633+ -- TODO: create a ThunkPtr from the branch name
634+ _ <- unpackThunk' noTrail thunkDir
635+ -- TODO: if git checkout branch errors out, the directory should be restored back to it's previous state
636+ callProcessAndLogOutput (Debug, Error) $ gitProc thunkDir ["checkout", branch]
637+ _ <- packThunk' noTrail thunkDir
638+ updateThunkToLatest thunkDir
639+ -- TODO: use overwriteThunk thunkDir (someThunkPtr)
640+ Right (ThunkData_Checkout _) -> do
641+ callProcessAndLogOutput (Debug, Error) $ gitProc thunkDir ["checkout", branch]
642+ _ <- packThunk' noTrail thunkDir
643+ updateThunkToLatest thunkDir
639644
640645getThunkPtr :: MonadObelisk m => FilePath -> m ThunkPtr
641646getThunkPtr = getThunkPtr' True