mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 19:09:45 +00:00
Replace deprecated modules
Replace go-homedir with builtin os.UserHomeDir and pkg/errors with builtin errors
This commit is contained in:
2
go.mod
2
go.mod
@@ -5,9 +5,7 @@ go 1.16
|
||||
require (
|
||||
github.com/karrick/godirwalk v1.15.6
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/spf13/cobra v1.0.0
|
||||
github.com/spf13/viper v1.7.0
|
||||
github.com/stretchr/testify v1.6.0
|
||||
|
||||
3
go.sum
3
go.sum
@@ -126,7 +126,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
||||
@@ -145,8 +144,6 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
|
||||
@@ -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