Skip to content

Commit

Permalink
Fix error "Could not parse any remotes from the output of `git remote…
Browse files Browse the repository at this point in the history
… --verbose`." (#1266)
  • Loading branch information
srghma committed Aug 16, 2024
1 parent ac3c117 commit b2bc2ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/Spago/Git.purs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,14 @@ getGit = do

parseRemote :: String -> Maybe Remote
parseRemote = \line ->
case String.split (Pattern "\t") line of
[ name, secondPart ]
| [ url, _ ] <- String.split (Pattern " ") secondPart
, Just [ _, _, Just owner, Just repo ] <- NEA.toArray <$> Regex.match gitUrlRegex url ->
case Regex.split tabOrSpaceRegex line of
[ name, url, _ ]
| Just [ _, _, _, Just owner, Just repo ] <- NEA.toArray <$> Regex.match gitUrlRegex url ->
Just { name, url, owner, repo }
_ ->
Nothing
where
tabOrSpaceRegex = unsafePartial $ fromJust $ hush $
Regex.regex "\\s+" mempty
gitUrlRegex = unsafePartial $ fromJust $ hush $
Regex.regex "^(.+@.+:|https?:\\/\\/.+\\/)(.*)\\/(.+)\\.git$" mempty
Regex.regex "^((ssh:\\/\\/)?[^@]+@[^:]+[:\\/]|https?:\\/\\/[^\\/]+\\/)(.*)\\/(.+)\\.git$" mempty
18 changes: 17 additions & 1 deletion test/Spago/Unit/Git.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,30 @@ spec = do
Spec.it "parses a remote with a git protocol" do
parseRemote "origin\tgit@github.com:foo/bar.git (fetch)"
`shouldEqual` Just { name: "origin", url: "git@github.com:foo/bar.git", owner: "foo", repo: "bar" }
parseRemote "origin git@github.com:foo/bar.git (fetch)"
`shouldEqual` Just { name: "origin", url: "git@github.com:foo/bar.git", owner: "foo", repo: "bar" }

Spec.it "parses a remote with an https protocol" do
parseRemote "origin\thttps://github.com/foo/bar.git (push)"
`shouldEqual` Just { name: "origin", url: "https://github.com/foo/bar.git", owner: "foo", repo: "bar" }
parseRemote "origin https://github.com/foo/bar.git (push)"
`shouldEqual` Just { name: "origin", url: "https://github.com/foo/bar.git", owner: "foo", repo: "bar" }

Spec.it "parses a remote with an ssh protocol" do
parseRemote "origin\tssh://git@github.com/foo/bar.git (push)"
`shouldEqual` Just { name: "origin", url: "ssh://git@github.com/foo/bar.git", owner: "foo", repo: "bar" }
parseRemote "origin ssh://git@github.com/foo/bar.git (push)"
`shouldEqual` Just { name: "origin", url: "ssh://git@github.com/foo/bar.git", owner: "foo", repo: "bar" }

Spec.it "rejects malformed remotes" do
parseRemote "origin\tgit@github.com:foo/bar.git" `shouldEqual` Nothing
parseRemote "origin git@github.com:foo/bar.git" `shouldEqual` Nothing

parseRemote "origin\tgit@github.com:foo/bar (push)" `shouldEqual` Nothing
parseRemote "origin git@github.com:foo/bar.git (fetch)" `shouldEqual` Nothing
parseRemote "origin git@github.com:foo/bar (push)" `shouldEqual` Nothing

parseRemote "origin\tgit@github.com:foo.git (push)" `shouldEqual` Nothing
parseRemote "origin git@github.com:foo.git (push)" `shouldEqual` Nothing

parseRemote "origin\thttps://foo.com/bar.git (push)" `shouldEqual` Nothing
parseRemote "origin https://foo.com/bar.git (push)" `shouldEqual` Nothing

0 comments on commit b2bc2ae

Please sign in to comment.