on master help sign in
Merge branch 'ob-thunk-set' of github.com:obsidiansystems/obelisk into ob-thunk-set
commit188d6122ba9bda142a11e98181664266edafc135 authorhsloan <ishaqsloan@gmail.com> dateThu 6 Dec 2018, 17:16 (8 years ago) parent3358cee4627ae6
4 files changed+29−19
lib/command/obelisk-command.cabal+1 lib/command/src/Obelisk/Command/Thunk.hs+3−1 lib/command/src/Obelisk/Command/Utils.hs+8−18 lib/selftest/src/Obelisk/SelfTest.hs+17
lib/command/obelisk-command.cabal+1
@@ -19,6 +19,7 @@ library
1919 , data-default
2020 , directory
2121 , either
22+ , errors
2223 , filepath
2324 , github
2425 , here
lib/command/src/Obelisk/Command/Thunk.hs+3−1
@@ -33,6 +33,7 @@ module Obelisk.Command.Thunk
3333
3434import Control.Applicative
3535import Control.Exception (displayException, try)
36+import Control.Error.Safe
3637import qualified Control.Lens as Lens
3738import Control.Lens.Indexed hiding ((<.>))
3839import Control.Monad
@@ -882,9 +883,10 @@ gitThunkRev s commit = do
882883gitGetCommitBranch
883884 :: MonadObelisk m => URI -> Maybe Text -> m (Text, CommitId)
884885gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote " <> uriMsg) $ do
885− bothMaps <- gitLsRemote
886+ (_, bothMaps) <- gitLsRemote
886887 (T.unpack $ render uri)
887888 (GitRef_Branch <$> mbranch)
889+ Nothing
888890 branch <- case mbranch of
889891 Nothing -> withExitFailMessage "Failed to find default branch" $ do
890892 b <- rethrowE $ gitLookupDefaultBranch bothMaps
lib/command/src/Obelisk/Command/Utils.hs+8−18
@@ -123,25 +123,15 @@ gitLsRemote
123123 :: MonadObelisk m
124124 => String
125125 -> Maybe GitRef
126− -> m GitLsRemoteMaps
127−gitLsRemote repository mRef = do
128− t <- readProc $ gitProcNoRepo $
129− ["ls-remote", "--symref", repository]
130− ++ (maybeToList $ T.unpack . showGitRef <$> mRef)
131− maps <- case MP.runParser parseLsRemote "" t of
132− Left err -> failWith $ T.pack $ MP.parseErrorPretty' t err
133− Right table -> pure $ bimap M.fromList M.fromList $ partitionEithers $ table
134− putLog Debug $ "git ls-remote maps: " <> T.pack (show maps)
135− pure maps
136−
137−gitLsRemoteExitCode
138− :: MonadObelisk m
139− => String
140− -> String
126+ -> Maybe String
141127 -> m (ExitCode, GitLsRemoteMaps)
142−gitLsRemoteExitCode repository branchName = do
143− (exitCode, out, _err) <- readCreateProcessWithExitCode $ gitProcNoRepo $
144− ["ls-remote", "--exit-code", repository, branchName]
128+gitLsRemote repository mRef mBranch = do
129+ (exitCode, out, _err) <- case mBranch of
130+ Nothing -> readCreateProcessWithExitCode $ gitProcNoRepo $
131+ ["ls-remote", "--exit-code", "--symref", repository]
132+ ++ (maybeToList $ T.unpack . showGitRef <$> mRef)
133+ Just branchName -> readCreateProcessWithExitCode $ gitProcNoRepo $
134+ ["ls-remote", "--exit-code", repository, branchName]
145135 let t = T.pack out
146136 maps <- case MP.runParser parseLsRemote "" t of
147137 Left err -> failWith $ T.pack $ MP.parseErrorPretty' t err
lib/selftest/src/Obelisk/SelfTest.hs+17
@@ -213,6 +213,23 @@ main = do
213213 void $ unpack
214214 testThunkPack (dir </> thunk)
215215
216+ describe "ob thunk update --branch" $ parallel $ do
217+ it "can change a thunk to the latest version of a desired branch" $ withTmp $ \dir -> do
218+ let branch1 = "master"
219+ branch2 = "develop"
220+ run_ "git" ["clone", "https://github.com/reflex-frp/reflex.git", toTextIgnore dir, "--branch", branch1]
221+ run_ "ob" ["thunk" , "pack", toTextIgnore dir]
222+ run_ "ob" ["thunk", "update", toTextIgnore dir, "--branch", branch2]
223+
224+ it "doesn't create anything when given an invalid branch" $ withTmp $ \dir -> do
225+ let checkDir dir' = liftIO $ getDirectoryContents $ T.unpack $ toTextIgnore dir'
226+ run_ "git" ["clone", "https://github.com/reflex-frp/reflex.git", toTextIgnore dir, "--branch", "master"]
227+ run_ "ob" ["thunk" , "pack", toTextIgnore dir]
228+ startingContents <- checkDir dir
229+ void $ errExit False $ run "ob" ["thunk", "update", toTextIgnore dir, "--branch", "dumble-palooza"]
230+ checkDir dir >>= liftIO . assertEqual "" startingContents
231+
232+
216233-- | Run `ob run` in the given directory (maximum of one level deep)
217234testObRunInDir :: Socket.PortNumber -> Socket.PortNumber -> Maybe Shelly.FilePath -> HTTP.Manager -> Sh ()
218235testObRunInDir p0 p1 mdir httpManager = handle_sh (\case ExitSuccess -> pure (); e -> throw e) $ do