diff --git a/go.mod b/go.mod index f0d72b2..ad9943d 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index de6fbfb..0845c2d 100644 --- a/go.sum +++ b/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= diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index 2caa2c5..09f3cdb 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -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) + } } } diff --git a/pkg/dump.go b/pkg/dump.go index 0ffd6c3..ecb923f 100644 --- a/pkg/dump.go +++ b/pkg/dump.go @@ -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) diff --git a/pkg/git/finder.go b/pkg/git/finder.go index 0ee90bd..61647e0 100644 --- a/pkg/git/finder.go +++ b/pkg/git/finder.go @@ -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. diff --git a/pkg/git/finder_test.go b/pkg/git/finder_test.go index 1ab2078..dd2f78e 100644 --- a/pkg/git/finder_test.go +++ b/pkg/git/finder_test.go @@ -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/", diff --git a/pkg/url.go b/pkg/url.go index 5715cf0..8ee2754 100644 --- a/pkg/url.go +++ b/pkg/url.go @@ -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) } }