8000 plumbing: transport/file, Change paths to absolute by pjbgf · Pull Request #1141 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content

plumbing: transport/file, Change paths to absolute #1141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
plumbing: transport/file, Change paths to absolute
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
  • Loading branch information
pjbgf committed Jul 13, 2024
commit 9550dfab10f009362b4921bc7f45996d9ff6ce5e
7 changes: 6 additions & 1 deletion plumbing/transport/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"net/url"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -295,7 +296,11 @@ func parseFile(endpoint string) (*Endpoint, bool) {
return nil, false
}

path := endpoint
path, err := filepath.Abs(endpoint)
if err != nil {
return nil, false
}

return &Endpoint{
Protocol: "file",
Path: path,
Expand Down
35 changes: 29 additions & 6 deletions plumbing/transport/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package transport
import (
"fmt"
"net/url"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/go-git/go-git/v5/plumbing/protocol/packp/capability"
Expand Down Expand Up @@ -120,39 +123,59 @@ func (s *SuiteCommon) TestNewEndpointSCPLikeWithPort(c *C) {
}

func (s *SuiteCommon) TestNewEndpointFileAbs(c *C) {
var err error
abs := "/foo.git"

if runtime.GOOS == "windows" {
abs, err = filepath.Abs(abs)
c.Assert(err, IsNil)
}

e, err := NewEndpoint("/foo.git")
c.Assert(err, IsNil)
c.Assert(e.Protocol, Equals, "file")
c.Assert(e.User, Equals, "")
c.Assert(e.Password, Equals, "")
c.Assert(e.Host, Equals, "")
c.Assert(e.Port, Equals, 0)
c.Assert(e.Path, Equals, "/foo.git")
c.Assert(e.String(), Equals, "file:///foo.git")
c.Assert(e.Path, Equals, abs)
c.Assert(e.String(), Equals, "file://"+abs)
}

func (s *SuiteCommon) TestNewEndpointFileRel(c *C) {
abs, err := filepath.Abs("foo.git")
c.Assert(err, IsNil)

e, err := NewEndpoint("foo.git")
c.Assert(err, IsNil)
c.Assert(e.Protocol, Equals, "file")
c.Assert(e.User, Equals, "")
c.Assert(e.Password, Equals, "")
c.Assert(e.Host, Equals, "")
c.Assert(e.Port, Equals, 0)
c.Assert(e.Path, Equals, "foo.git")
c.Assert(e.String(), Equals, "file://foo.git")
c.Assert(e.Path, Equals, abs)
c.Assert(e.String(), Equals, "file://"+abs)
}

func (s *SuiteCommon) TestNewEndpointFileWindows(c *C) {
abs := "C:\\foo.git"

if runtime.GOOS != "windows" {
cwd, err := os.Getwd()
c.Assert(err, IsNil)

abs = filepath.Join(cwd, "C:\\foo.git")
}

e, err := NewEndpoint("C:\\foo.git")
c.Assert(err, IsNil)
c.Assert(e.Protocol, Equals, "file")
c.Assert(e.User, Equals, "")
c.Assert(e.Password, Equals, "")
c.Assert(e.Host, Equals, "")
c.Assert(e.Port, Equals, 0)
c.Assert(e.Path, Equals, "C:\\foo.git")
c.Assert(e.String(), Equals, "file://C:\\foo.git")
c.Assert(e.Path, Equals, abs)
c.Assert(e.String(), Equals, "file://"+abs)
}

func (s *SuiteCommon) TestNewEndpointFileURL(c *C) {
Loading
0