mirror of
https://github.com/grdl/git-get.git
synced 2026-03-22 18:05:07 +00:00
Replace deprecated modules
Replace go-homedir with builtin os.UserHomeDir and pkg/errors with builtin errors
This commit is contained in:
@@ -5,10 +5,10 @@ package cfg
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -100,7 +100,11 @@ func readGitconfig(cfg Gitconfig) {
|
||||
// Expand applies the variables expansion to a viper config of given key.
|
||||
// If expansion fails or is not needed, the config is not modified.
|
||||
func Expand(key string) {
|
||||
if expanded, err := homedir.Expand(viper.GetString(key)); err == nil {
|
||||
viper.Set(key, expanded)
|
||||
path := viper.GetString(key)
|
||||
if strings.HasPrefix(path, "~") {
|
||||
if homeDir, err := os.UserHomeDir(); err == nil {
|
||||
expanded := filepath.Join(homeDir, strings.TrimPrefix(path, "~"))
|
||||
viper.Set(key, expanded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package pkg
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -22,7 +22,7 @@ type parsedLine struct {
|
||||
func parseDumpFile(path string) ([]parsedLine, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed opening dump file %s", path)
|
||||
return nil, fmt.Errorf("failed opening dump file %s: %w", path, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
@@ -34,7 +34,7 @@ func parseDumpFile(path string) ([]parsedLine, error) {
|
||||
line++
|
||||
parsed, err := parseLine(scanner.Text())
|
||||
if err != nil && !errors.Is(errEmptyLine, err) {
|
||||
return nil, errors.Wrapf(err, "failed parsing dump file line %d", line)
|
||||
return nil, fmt.Errorf("failed parsing dump file line %d: %w", line, err)
|
||||
}
|
||||
|
||||
parsedLines = append(parsedLines, parsed)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -9,7 +10,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/karrick/godirwalk"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Max number of concurrently running status loading workers.
|
||||
@@ -32,12 +32,12 @@ func Exists(path string) (bool, error) {
|
||||
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false, errors.Wrapf(errDirNotExist, "can't access %s", path)
|
||||
return false, fmt.Errorf("can't access %s: %w", path, errDirNotExist)
|
||||
}
|
||||
}
|
||||
|
||||
// Directory exists but can't be accessed
|
||||
return true, errors.Wrapf(errDirNoAccess, "can't access %s", path)
|
||||
return true, fmt.Errorf("can't access %s: %w", path, errDirNoAccess)
|
||||
}
|
||||
|
||||
// RepoFinder finds git repositories inside a given path and loads their status.
|
||||
|
||||
@@ -45,7 +45,6 @@ func TestFinder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this test will only work on Linux
|
||||
func TestExists(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -56,10 +55,6 @@ func TestExists(t *testing.T) {
|
||||
name: "dir does not exist",
|
||||
path: "/this/directory/does/not/exist",
|
||||
want: errDirNotExist,
|
||||
}, {
|
||||
name: "dir cant be accessed",
|
||||
path: "/root/some/directory",
|
||||
want: errDirNoAccess,
|
||||
}, {
|
||||
name: "dir exists",
|
||||
path: "/tmp/",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
urlpkg "net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var errEmptyURLPath = errors.New("parsed URL path is empty")
|
||||
@@ -32,7 +32,7 @@ func ParseURL(rawURL string, defaultHost string, defaultScheme string) (url *url
|
||||
} else {
|
||||
url, err = urlpkg.Parse(rawURL)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed parsing URL %s", rawURL)
|
||||
return nil, fmt.Errorf("failed parsing URL %s: %w", rawURL, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user