on master help sign in
consolidate gitLsRemote and gitLsRemoteExitCode into one function
commitff0c145aab40541b25e66e297da654cf2fdac525 authorhsloan <ishaqsloan@gmail.com> dateFri 30 Nov 2018, 17:52 (8 years ago) parenta62526e
2 files changed+11−20
lib/command/src/Obelisk/Command/Thunk.hs+3−2 lib/command/src/Obelisk/Command/Utils.hs+8−18
lib/command/src/Obelisk/Command/Thunk.hs+3−2
@@ -636,7 +636,7 @@ setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>
636636 ThunkSource_Git gitSource -> T.unpack $ render $ _gitSource_url gitSource
637637 ThunkSource_GitHub gitHubSource -> T.unpack $ render $ _gitSource_url $ forgetGithub True gitHubSource
638638 -- check to see if branch exists before modifying directory
639− (exitCode, _) <- gitLsRemoteExitCode repository branch
639+ (exitCode, _) <- gitLsRemote repository Nothing $ Just branch
640640 case exitCode of
641641 ExitSuccess -> do
642642 remoteResults <- readGitProcessNoRepo ["ls-remote", repository, branch]
@@ -903,9 +903,10 @@ gitThunkRev s commit = do
903903gitGetCommitBranch
904904 :: MonadObelisk m => URI -> Maybe Text -> m (Text, CommitId)
905905gitGetCommitBranch uri mbranch = withExitFailMessage ("Failure for git remote " <> uriMsg) $ do
906− bothMaps <- gitLsRemote
906+ (_, bothMaps) <- gitLsRemote
907907 (T.unpack $ render uri)
908908 (GitRef_Branch <$> mbranch)
909+ Nothing
909910 branch <- case mbranch of
910911 Nothing -> withExitFailMessage "Failed to find default branch" $ do
911912 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