6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-10 03:49:25 +00:00

Replace deprecated modules

Replace go-homedir with builtin os.UserHomeDir and pkg/errors with
builtin errors
This commit is contained in:
Grzegorz Dlugoszewski
2025-08-11 20:43:49 +02:00
parent 8cd27a8f62
commit 7ecef9c85d
7 changed files with 17 additions and 23 deletions

2
go.mod
View File

@@ -5,9 +5,7 @@ go 1.16
require ( require (
github.com/karrick/godirwalk v1.15.6 github.com/karrick/godirwalk v1.15.6
github.com/kr/text v0.2.0 // indirect 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/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/cobra v1.0.0
github.com/spf13/viper v1.7.0 github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.6.0 github.com/stretchr/testify v1.6.0

3
go.sum
View File

@@ -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/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= 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.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-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/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= 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/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.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=

View File

@@ -5,10 +5,10 @@ package cfg
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@@ -100,7 +100,11 @@ func readGitconfig(cfg Gitconfig) {
// Expand applies the variables expansion to a viper config of given key. // Expand applies the variables expansion to a viper config of given key.
// If expansion fails or is not needed, the config is not modified. // If expansion fails or is not needed, the config is not modified.
func Expand(key string) { func Expand(key string) {
if expanded, err := homedir.Expand(viper.GetString(key)); err == nil { path := viper.GetString(key)
viper.Set(key, expanded) if strings.HasPrefix(path, "~") {
if homeDir, err := os.UserHomeDir(); err == nil {
expanded := filepath.Join(homeDir, strings.TrimPrefix(path, "~"))
viper.Set(key, expanded)
}
} }
} }

View File

@@ -2,10 +2,10 @@ package pkg
import ( import (
"bufio" "bufio"
"errors"
"fmt"
"os" "os"
"strings" "strings"
"github.com/pkg/errors"
) )
var ( var (
@@ -22,7 +22,7 @@ type parsedLine struct {
func parseDumpFile(path string) ([]parsedLine, error) { func parseDumpFile(path string) ([]parsedLine, error) {
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { 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() defer file.Close()
@@ -34,7 +34,7 @@ func parseDumpFile(path string) ([]parsedLine, error) {
line++ line++
parsed, err := parseLine(scanner.Text()) parsed, err := parseLine(scanner.Text())
if err != nil && !errors.Is(errEmptyLine, err) { 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) parsedLines = append(parsedLines, parsed)

View File

@@ -1,6 +1,7 @@
package git package git
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@@ -9,7 +10,6 @@ import (
"syscall" "syscall"
"github.com/karrick/godirwalk" "github.com/karrick/godirwalk"
"github.com/pkg/errors"
) )
// Max number of concurrently running status loading workers. // Max number of concurrently running status loading workers.
@@ -32,12 +32,12 @@ func Exists(path string) (bool, error) {
if err != nil { if err != nil {
if os.IsNotExist(err) { 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 // 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. // RepoFinder finds git repositories inside a given path and loads their status.

View File

@@ -45,7 +45,6 @@ func TestFinder(t *testing.T) {
} }
} }
// TODO: this test will only work on Linux
func TestExists(t *testing.T) { func TestExists(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
@@ -56,10 +55,6 @@ func TestExists(t *testing.T) {
name: "dir does not exist", name: "dir does not exist",
path: "/this/directory/does/not/exist", path: "/this/directory/does/not/exist",
want: errDirNotExist, want: errDirNotExist,
}, {
name: "dir cant be accessed",
path: "/root/some/directory",
want: errDirNoAccess,
}, { }, {
name: "dir exists", name: "dir exists",
path: "/tmp/", path: "/tmp/",

View File

@@ -1,13 +1,13 @@
package pkg package pkg
import ( import (
"errors"
"fmt"
urlpkg "net/url" urlpkg "net/url"
"path" "path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"github.com/pkg/errors"
) )
var errEmptyURLPath = errors.New("parsed URL path is empty") var errEmptyURLPath = errors.New("parsed URL path is empty")
@@ -32,7 +32,7 @@ func ParseURL(rawURL string, defaultHost string, defaultScheme string) (url *url
} else { } else {
url, err = urlpkg.Parse(rawURL) url, err = urlpkg.Parse(rawURL)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed parsing URL %s", rawURL) return nil, fmt.Errorf("failed parsing URL %s: %w", rawURL, err)
} }
} }