aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2024-07-13 10:11:01 +0100
committerPaulo Gomes <pjbgf@linux.com>2024-07-13 10:11:01 +0100
commit9550dfab10f009362b4921bc7f45996d9ff6ce5e (patch)
tree25d82cfcfe1aebfef27d301c28a8bf72993ffd11
parent94fb0d8e1a77fd962c0dde4bed08ce59bc5cfba2 (diff)
downloadgo-git-9550dfab10f009362b4921bc7f45996d9ff6ce5e.tar.gz
plumbing: transport/file, Change paths to absolute
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
-rw-r--r--plumbing/transport/common.go7
-rw-r--r--plumbing/transport/common_test.go35
2 files changed, 35 insertions, 7 deletions
diff --git a/plumbing/transport/common.go b/plumbing/transport/common.go
index b05437f..fae1aa9 100644
--- a/plumbing/transport/common.go
+++ b/plumbing/transport/common.go
@@ -19,6 +19,7 @@ import (
"fmt"
"io"
"net/url"
+ "path/filepath"
"strconv"
"strings"
@@ -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,
diff --git a/plumbing/transport/common_test.go b/plumbing/transport/common_test.go
index 3efc555..1501f73 100644
--- a/plumbing/transport/common_test.go
+++ b/plumbing/transport/common_test.go
@@ -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"
@@ -120,6 +123,14 @@ 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")
@@ -127,11 +138,14 @@ func (s *SuiteCommon) TestNewEndpointFileAbs(c *C) {
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")
@@ -139,11 +153,20 @@ func (s *SuiteCommon) TestNewEndpointFileRel(c *C) {
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")
@@ -151,8 +174,8 @@ func (s *SuiteCommon) TestNewEndpointFileWindows(c *C) {
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) {