Skip to content

Commit 2520670

Browse files
authored
Allow for missing .git when parsing repository addresses (#1335)
1 parent 4381814 commit 2520670

File tree

3 files changed

+62
-31
lines changed

3 files changed

+62
-31
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Other improvements:
5252
- Restored broken type-directed search in generated docs.
5353
- `spago graph modules` now correctly reports extra-packages located outside the
5454
workspace root.
55+
- on `spago publish` - add support for urls without `.git` suffix.
56+
Before: `ssh://[email protected]/foo/bar.git` - ok, `ssh://[email protected]/foo/bar` - error
57+
After: `ssh://[email protected]/foo/bar.git` - ok, `ssh://[email protected]/foo/bar` - ok
5558

5659
## [0.21.0] - 2023-05-04
5760

src/Spago/Git.purs

+4-7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import Control.Monad.Except (ExceptT(..))
2222
import Control.Monad.Except as Except
2323
import Data.Array as Array
2424
import Data.Array.NonEmpty as NEA
25-
import Data.Maybe (fromJust)
2625
import Data.String (Pattern(..))
2726
import Data.String as String
28-
import Data.String.Regex as Regex
29-
import Partial.Unsafe (unsafePartial)
27+
import Data.String.Regex (match, split) as Regex
28+
import Data.String.Regex.Unsafe (unsafeRegex) as Regex
3029
import Registry.Version as Version
3130
import Spago.Cmd as Cmd
3231
import Spago.FS as FS
@@ -197,7 +196,5 @@ parseRemote = \line ->
197196
_ ->
198197
Nothing
199198
where
200-
tabOrSpaceRegex = unsafePartial $ fromJust $ hush $
201-
Regex.regex "\\s+" mempty
202-
gitUrlRegex = unsafePartial $ fromJust $ hush $
203-
Regex.regex "^((ssh:\\/\\/)?[^@]+@[^:]+[:\\/]|https?:\\/\\/[^\\/]+\\/)(.*)\\/(.+)\\.git$" mempty
199+
tabOrSpaceRegex = Regex.unsafeRegex """\s+""" mempty
200+
gitUrlRegex = Regex.unsafeRegex """^((ssh:\/\/)?[^@]+@[^:]+[:\/]|https?:\/\/[^\/]+\/)([^\/]+)\/([^\/]+?)(?:\.git)?$""" mempty

test/Spago/Unit/Git.purs

+55-24
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,65 @@ spec :: Spec Unit
1111
spec = do
1212
Spec.describe "Git" do
1313
Spec.describe "parseRemote" do
14+
Spec.describe "successfully parses" do
15+
let
16+
mkTest input expectedUrl = Spec.it input $ parseRemote input `shouldEqual` Just { name: "origin", url: expectedUrl, owner: "foo", repo: "bar" }
1417

15-
Spec.it "parses a remote with a git protocol" do
16-
parseRemote "origin\t[email protected]:foo/bar.git (fetch)"
17-
`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" }
18+
Spec.describe "remote with a git protocol" do
19+
mkTest "origin\t[email protected]:foo/bar.git (fetch)" "[email protected]:foo/bar.git"
20+
mkTest "origin [email protected]:foo/bar.git (fetch)" "[email protected]:foo/bar.git"
21+
-- spago should be tolerant to missing .git
22+
mkTest "origin\t[email protected]:foo/bar (fetch)" "[email protected]:foo/bar"
23+
mkTest "origin [email protected]:foo/bar (fetch)" "[email protected]:foo/bar"
2024

21-
Spec.it "parses a remote with an https protocol" do
22-
parseRemote "origin\thttps://github.com/foo/bar.git (push)"
23-
`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" }
25+
Spec.describe "remote with an https protocol" do
26+
mkTest "origin\thttps://github.com/foo/bar.git (push)" "https://github.com/foo/bar.git"
27+
mkTest "origin https://github.com/foo/bar.git (push)" "https://github.com/foo/bar.git"
28+
-- spago should be tolerant to missing .git
29+
mkTest "origin\thttps://github.com/foo/bar (push)" "https://github.com/foo/bar"
30+
mkTest "origin https://github.com/foo/bar (push)" "https://github.com/foo/bar"
2631

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" }
32+
Spec.describe "remote with an https protocol" do
33+
mkTest "origin\thttp://github.com/foo/bar.git (push)" "http://github.com/foo/bar.git"
34+
mkTest "origin http://github.com/foo/bar.git (push)" "http://github.com/foo/bar.git"
35+
-- spago should be tolerant to missing .git
36+
mkTest "origin\thttp://github.com/foo/bar (push)" "http://github.com/foo/bar"
37+
mkTest "origin http://github.com/foo/bar (push)" "http://github.com/foo/bar"
3238

33-
Spec.it "rejects malformed remotes" do
34-
parseRemote "origin\t[email protected]:foo/bar.git" `shouldEqual` Nothing
35-
parseRemote "origin [email protected]:foo/bar.git" `shouldEqual` Nothing
39+
Spec.describe "remote with an ssh protocol" do
40+
mkTest "origin\tssh://[email protected]/foo/bar.git (push)" "ssh://[email protected]/foo/bar.git"
41+
mkTest "origin ssh://[email protected]/foo/bar.git (push)" "ssh://[email protected]/foo/bar.git"
42+
-- spago should be tolerant to missing .git
43+
mkTest "origin\tssh://[email protected]/foo/bar (push)" "ssh://[email protected]/foo/bar"
44+
mkTest "origin ssh://[email protected]/foo/bar (push)" "ssh://[email protected]/foo/bar"
3645

37-
parseRemote "origin\t[email protected]:foo/bar (push)" `shouldEqual` Nothing
38-
parseRemote "origin [email protected]:foo/bar (push)" `shouldEqual` Nothing
46+
Spec.describe "rejects" do
47+
let mkTest input = Spec.it input $ parseRemote input `shouldEqual` Nothing
3948

40-
parseRemote "origin\t[email protected]:foo.git (push)" `shouldEqual` Nothing
41-
parseRemote "origin [email protected]:foo.git (push)" `shouldEqual` Nothing
49+
Spec.describe "rejects malformed remotes" do
50+
Spec.describe "missing trailing (push) or (fetch) field" do
51+
-- yes, not possible even if edit .git/config
52+
mkTest "origin\t[email protected]:foo/bar.git"
53+
mkTest "origin [email protected]:foo/bar.git"
4254

43-
parseRemote "origin\thttps://foo.com/bar.git (push)" `shouldEqual` Nothing
44-
parseRemote "origin https://foo.com/bar.git (push)" `shouldEqual` Nothing
55+
Spec.describe "missing repo name (with or without .git given)" do
56+
-- git
57+
mkTest "origin\t[email protected]:foo.git (push)"
58+
mkTest "origin [email protected]:foo.git (push)"
59+
mkTest "origin\t[email protected]:foo (push)"
60+
mkTest "origin [email protected]:foo (push)"
61+
-- https
62+
mkTest "origin\thttps://github.com:foo.git (push)"
63+
mkTest "origin https://github.com:foo.git (push)"
64+
mkTest "origin\thttps://github.com:foo (push)"
65+
mkTest "origin https://github.com:foo (push)"
66+
-- http
67+
mkTest "origin\thttp://github.com:foo.git (push)"
68+
mkTest "origin http://github.com:foo.git (push)"
69+
mkTest "origin\thttp://github.com:foo (push)"
70+
mkTest "origin http://github.com:foo (push)"
71+
-- ssh
72+
mkTest "origin\tssh://github.com:foo.git (push)"
73+
mkTest "origin ssh://github.com:foo.git (push)"
74+
mkTest "origin\tssh://github.com:foo (push)"
75+
mkTest "origin ssh://github.com:foo (push)"

0 commit comments

Comments
 (0)