Add a helper function

This commit is contained in:
Filip Gralinski 2019-12-07 21:26:50 +01:00
parent 8e22fa1043
commit 247e55ba18

View File

@ -251,6 +251,14 @@ cloneRepo' userId repoCloningSpec chan = do
err chan "git failed" err chan "git failed"
return Nothing return Nothing
-- An auxilliary function for fixing git URLs.
-- By default, this does nothing, but can be changed
-- in Gonito forks.
-- Should be used just before a raw git command is executed
-- (i.e. its changes will not be reflected in the database).
fixGitRepoUrl :: Text -> Text
fixGitRepoUrl = id
rawClone :: FilePath -> RepoCloningSpec -> Channel -> Handler ExitCode rawClone :: FilePath -> RepoCloningSpec -> Channel -> Handler ExitCode
rawClone tmpRepoDir repoCloningSpec chan = runWithChannel chan $ do rawClone tmpRepoDir repoCloningSpec chan = runWithChannel chan $ do
let url = repoSpecUrl $ cloningSpecRepo repoCloningSpec let url = repoSpecUrl $ cloningSpecRepo repoCloningSpec
@ -262,7 +270,7 @@ rawClone tmpRepoDir repoCloningSpec chan = runWithChannel chan $ do
"--single-branch", "--single-branch",
"--branch", "--branch",
T.unpack referenceBranch, T.unpack referenceBranch,
T.unpack referenceUrl, T.unpack (fixGitRepoUrl referenceUrl),
tmpRepoDir] tmpRepoDir]
if url /= referenceUrl || branch /= referenceBranch if url /= referenceUrl || branch /= referenceBranch
then then
@ -270,7 +278,7 @@ rawClone tmpRepoDir repoCloningSpec chan = runWithChannel chan $ do
runProg (Just tmpRepoDir) gitPath ["remote", runProg (Just tmpRepoDir) gitPath ["remote",
"set-url", "set-url",
"origin", "origin",
T.unpack url] T.unpack (fixGitRepoUrl url)]
runProg (Just tmpRepoDir) gitPath ["fetch", runProg (Just tmpRepoDir) gitPath ["fetch",
"origin", "origin",
T.unpack branch] T.unpack branch]