6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-08 09:19:18 +00:00

Replace path.Join with filepath.Join

Path is for URLs, filepath is for os paths. This solves the problem with wrong repo root on windows.
This commit is contained in:
Grzegorz Dlugoszewski
2020-06-30 11:25:49 +02:00
parent b8606568ef
commit 235ea0d811
4 changed files with 10 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"git-get/pkg/git" "git-get/pkg/git"
"git-get/pkg/io" "git-get/pkg/io"
"path" "path/filepath"
) )
// GetCfg provides configuration for the Get command. // GetCfg provides configuration for the Get command.
@@ -40,7 +40,7 @@ func cloneSingleRepo(c *GetCfg) error {
opts := &git.CloneOpts{ opts := &git.CloneOpts{
URL: url, URL: url,
Path: path.Join(c.Root, URLToPath(url)), Path: filepath.Join(c.Root, URLToPath(url)),
Branch: c.Branch, Branch: c.Branch,
} }
@@ -63,7 +63,7 @@ func cloneDumpFile(c *GetCfg) error {
opts := &git.CloneOpts{ opts := &git.CloneOpts{
URL: url, URL: url,
Path: path.Join(c.Root, URLToPath(url)), Path: filepath.Join(c.Root, URLToPath(url)),
Branch: line.branch, Branch: line.branch,
} }

View File

@@ -4,7 +4,7 @@ import (
"git-get/pkg/io" "git-get/pkg/io"
"git-get/pkg/run" "git-get/pkg/run"
"git-get/pkg/test" "git-get/pkg/test"
"path" "path/filepath"
"testing" "testing"
) )
@@ -75,7 +75,7 @@ func TestGitConfig(t *testing.T) {
func makeConfigEmpty(t *testing.T) *cfgStub { func makeConfigEmpty(t *testing.T) *cfgStub {
c := newCfgStub(t) c := newCfgStub(t)
io.Write(path.Join(c.repo.Path(), dotgit, "config"), "") io.Write(filepath.Join(c.repo.Path(), dotgit, "config"), "")
return c return c
} }
@@ -89,7 +89,7 @@ func makeConfigValid(t *testing.T) *cfgStub {
[gitget] [gitget]
host = github.com host = github.com
` `
io.Write(path.Join(c.repo.Path(), dotgit, "config"), gitconfig) io.Write(filepath.Join(c.repo.Path(), dotgit, "config"), gitconfig)
return c return c
} }

View File

@@ -4,12 +4,12 @@ import (
"fmt" "fmt"
"git-get/pkg/io" "git-get/pkg/io"
"git-get/pkg/run" "git-get/pkg/run"
"path" "path/filepath"
"testing" "testing"
) )
func (r *Repo) writeFile(filename string, content string) { func (r *Repo) writeFile(filename string, content string) {
path := path.Join(r.path, filename) path := filepath.Join(r.path, filename)
err := io.Write(path, content) err := io.Write(path, content)
checkFatal(r.t, err) checkFatal(r.t, err)
} }

View File

@@ -2,7 +2,7 @@ package pkg
import ( import (
urlpkg "net/url" urlpkg "net/url"
"path" "path/filepath"
"regexp" "regexp"
"strings" "strings"
@@ -67,7 +67,7 @@ func URLToPath(url *urlpkg.URL) (repoPath string) {
repoHost := strings.Split(url.Host, ":")[0] repoHost := strings.Split(url.Host, ":")[0]
// Remove trailing ".git" from repo name // Remove trailing ".git" from repo name
repoPath = path.Join(repoHost, url.Path) repoPath = filepath.Join(repoHost, url.Path)
repoPath = strings.TrimSuffix(repoPath, ".git") repoPath = strings.TrimSuffix(repoPath, ".git")
// Remove tilde (~) char from username // Remove tilde (~) char from username