diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-06-05 20:09:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 20:09:44 +0100 |
commit | 42112780406835a867e6e8cce5ccca3adf13c803 (patch) | |
tree | f748128bfbd51dc07300c36335bf398d17a372af | |
parent | d4b7c8f42f0751cf34a3f4088dd9f00a63fd866b (diff) | |
parent | 9706315a961c52184e2f9111883b08df6ac702b8 (diff) | |
download | go-git-42112780406835a867e6e8cce5ccca3adf13c803.tar.gz |
Merge pull request #756 from matejrisek/fix/scp-style-submodule-url
git: fix the issue with submodules having the SCP style URL fail due to the wrong URL parsing
-rw-r--r-- | submodule.go | 14 | ||||
-rw-r--r-- | submodule_test.go | 26 |
2 files changed, 33 insertions, 7 deletions
diff --git a/submodule.go b/submodule.go index b0c4169..84f020d 100644 --- a/submodule.go +++ b/submodule.go @@ -5,13 +5,13 @@ import ( "context" "errors" "fmt" - "net/url" "path" "github.com/go-git/go-billy/v5" "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/format/index" + "github.com/go-git/go-git/v5/plumbing/transport" ) var ( @@ -133,29 +133,29 @@ func (s *Submodule) Repository() (*Repository, error) { return nil, err } - moduleURL, err := url.Parse(s.c.URL) + moduleEndpoint, err := transport.NewEndpoint(s.c.URL) if err != nil { return nil, err } - if !path.IsAbs(moduleURL.Path) { + if !path.IsAbs(moduleEndpoint.Path) && moduleEndpoint.Protocol == "file" { remotes, err := s.w.r.Remotes() if err != nil { return nil, err } - rootURL, err := url.Parse(remotes[0].c.URLs[0]) + rootEndpoint, err := transport.NewEndpoint(remotes[0].c.URLs[0]) if err != nil { return nil, err } - rootURL.Path = path.Join(rootURL.Path, moduleURL.Path) - *moduleURL = *rootURL + rootEndpoint.Path = path.Join(rootEndpoint.Path, moduleEndpoint.Path) + *moduleEndpoint = *rootEndpoint } _, err = r.CreateRemote(&config.RemoteConfig{ Name: DefaultRemoteName, - URLs: []string{moduleURL.String()}, + URLs: []string{moduleEndpoint.String()}, }) return r, err diff --git a/submodule_test.go b/submodule_test.go index 92943e1..0e88391 100644 --- a/submodule_test.go +++ b/submodule_test.go @@ -5,7 +5,10 @@ import ( "path/filepath" "testing" + "github.com/go-git/go-billy/v5/memfs" + "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/storage/memory" fixtures "github.com/go-git/go-git-fixtures/v4" . "gopkg.in/check.v1" @@ -258,3 +261,26 @@ func (s *SubmoduleSuite) TestSubmodulesFetchDepth(c *C) { c.Assert(commitCount, Equals, 1) } + +func (s *SubmoduleSuite) TestSubmoduleParseScp(c *C) { + repo := &Repository{ + Storer: memory.NewStorage(), + wt: memfs.New(), + } + worktree := &Worktree{ + Filesystem: memfs.New(), + r: repo, + } + submodule := &Submodule{ + initialized: true, + c: nil, + w: worktree, + } + + submodule.c = &config.Submodule{ + URL: "git@github.com:username/submodule_repo", + } + + _, err := submodule.Repository() + c.Assert(err, IsNil) +} |