Skip to content

Commit b2bc2ae

Browse files
author
Serhii Khoma
authored
Fix error "Could not parse any remotes from the output of git remote --verbose." (#1266)
1 parent ac3c117 commit b2bc2ae

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/Spago/Git.purs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ getGit = do
204204

205205
parseRemote :: String -> Maybe Remote
206206
parseRemote = \line ->
207-
case String.split (Pattern "\t") line of
208-
[ name, secondPart ]
209-
| [ url, _ ] <- String.split (Pattern " ") secondPart
210-
, Just [ _, _, Just owner, Just repo ] <- NEA.toArray <$> Regex.match gitUrlRegex url ->
207+
case Regex.split tabOrSpaceRegex line of
208+
[ name, url, _ ]
209+
| Just [ _, _, _, Just owner, Just repo ] <- NEA.toArray <$> Regex.match gitUrlRegex url ->
211210
Just { name, url, owner, repo }
212211
_ ->
213212
Nothing
214213
where
214+
tabOrSpaceRegex = unsafePartial $ fromJust $ hush $
215+
Regex.regex "\\s+" mempty
215216
gitUrlRegex = unsafePartial $ fromJust $ hush $
216-
Regex.regex "^(.+@.+:|https?:\\/\\/.+\\/)(.*)\\/(.+)\\.git$" mempty
217+
Regex.regex "^((ssh:\\/\\/)?[^@]+@[^:]+[:\\/]|https?:\\/\\/[^\\/]+\\/)(.*)\\/(.+)\\.git$" mempty

test/Spago/Unit/Git.purs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,30 @@ spec = do
1515
Spec.it "parses a remote with a git protocol" do
1616
parseRemote "origin\t[email protected]:foo/bar.git (fetch)"
1717
`shouldEqual` Just { name: "origin", url: "[email protected]:foo/bar.git", owner: "foo", repo: "bar" }
18+
parseRemote "origin [email protected]:foo/bar.git (fetch)"
19+
`shouldEqual` Just { name: "origin", url: "[email protected]:foo/bar.git", owner: "foo", repo: "bar" }
1820

1921
Spec.it "parses a remote with an https protocol" do
2022
parseRemote "origin\thttps://github.com/foo/bar.git (push)"
2123
`shouldEqual` Just { name: "origin", url: "https://github.com/foo/bar.git", owner: "foo", repo: "bar" }
24+
parseRemote "origin https://github.com/foo/bar.git (push)"
25+
`shouldEqual` Just { name: "origin", url: "https://github.com/foo/bar.git", owner: "foo", repo: "bar" }
26+
27+
Spec.it "parses a remote with an ssh protocol" do
28+
parseRemote "origin\tssh://[email protected]/foo/bar.git (push)"
29+
`shouldEqual` Just { name: "origin", url: "ssh://[email protected]/foo/bar.git", owner: "foo", repo: "bar" }
30+
parseRemote "origin ssh://[email protected]/foo/bar.git (push)"
31+
`shouldEqual` Just { name: "origin", url: "ssh://[email protected]/foo/bar.git", owner: "foo", repo: "bar" }
2232

2333
Spec.it "rejects malformed remotes" do
2434
parseRemote "origin\t[email protected]:foo/bar.git" `shouldEqual` Nothing
35+
parseRemote "origin [email protected]:foo/bar.git" `shouldEqual` Nothing
36+
2537
parseRemote "origin\t[email protected]:foo/bar (push)" `shouldEqual` Nothing
26-
parseRemote "origin [email protected]:foo/bar.git (fetch)" `shouldEqual` Nothing
38+
parseRemote "origin [email protected]:foo/bar (push)" `shouldEqual` Nothing
39+
2740
parseRemote "origin\t[email protected]:foo.git (push)" `shouldEqual` Nothing
41+
parseRemote "origin [email protected]:foo.git (push)" `shouldEqual` Nothing
42+
2843
parseRemote "origin\thttps://foo.com/bar.git (push)" `shouldEqual` Nothing
44+
parseRemote "origin https://foo.com/bar.git (push)" `shouldEqual` Nothing

0 commit comments

Comments
 (0)