Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Gomes <paulo.gomes@suse.com>
  • Loading branch information
pjbgf committed Mar 16, 2024
1 parent f883d3a commit 885fdc0
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 53 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func LoadConfig(scope Scope) (*Config, error) {
for _, file := range files {
f, err := osfs.Default.Open(file)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
continue
}

Expand Down
5 changes: 3 additions & 2 deletions plumbing/format/gitattributes/dir.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gitattributes

import (
"errors"
"os"

"github.com/go-git/go-billy/v5"
Expand All @@ -20,7 +21,7 @@ const (

func ReadAttributesFile(fs billy.Filesystem, path []string, attributesFile string, allowMacro bool) ([]MatchAttribute, error) {
f, err := fs.Open(fs.Join(append(path, attributesFile)...))
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
if err != nil {
Expand Down Expand Up @@ -79,7 +80,7 @@ func walkDirectory(fs billy.Filesystem, root []string) (attributes []MatchAttrib

func loadPatterns(fs billy.Filesystem, path string) ([]MatchAttribute, error) {
f, err := fs.Open(path)
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions plumbing/format/gitignore/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gitignore
import (
"bufio"
"bytes"
"errors"
"io"
"os"
"strings"
Expand Down Expand Up @@ -40,7 +41,7 @@ func readIgnoreFile(fs billy.Filesystem, path []string, ignoreFile string) (ps [
ps = append(ps, ParsePattern(s, path))
}
}
} else if !os.IsNotExist(err) {
} else if !errors.Is(err, os.ErrNotExist) {
return nil, err
}

Expand Down Expand Up @@ -82,7 +83,7 @@ func ReadPatterns(fs billy.Filesystem, path []string) (ps []Pattern, err error)
func loadPatterns(fs billy.Filesystem, path string) (ps []Pattern, err error) {
f, err := fs.Open(path)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
return nil, err
Expand All @@ -109,7 +110,7 @@ func loadPatterns(fs billy.Filesystem, path string) (ps []Pattern, err error) {
}

ps, err = readIgnoreFile(fs, nil, efo)
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}

Expand Down
5 changes: 3 additions & 2 deletions plumbing/transport/file/receive_pack_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package file

import (
"errors"
"os"

"github.com/go-git/go-git/v5/plumbing/transport/test"
Expand Down Expand Up @@ -41,7 +42,7 @@ func (s *ReceivePackSuite) TearDownTest(c *C) {
func (s *ReceivePackSuite) TestCommandNoOutput(c *C) {
c.Skip("failing test")

if _, err := os.Stat("/bin/true"); os.IsNotExist(err) {
if _, err := os.Stat("/bin/true"); errors.Is(err, os.ErrNotExist) {
c.Skip("/bin/true not found")
}

Expand All @@ -54,7 +55,7 @@ func (s *ReceivePackSuite) TestCommandNoOutput(c *C) {
}

func (s *ReceivePackSuite) TestMalformedInputNoErrors(c *C) {
if _, err := os.Stat("/usr/bin/yes"); os.IsNotExist(err) {
if _, err := os.Stat("/usr/bin/yes"); errors.Is(err, os.ErrNotExist) {
c.Skip("/usr/bin/yes not found")
}

Expand Down
5 changes: 3 additions & 2 deletions plumbing/transport/file/upload_pack_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package file

import (
"errors"
"os"

"github.com/go-git/go-git/v5/plumbing/transport"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
func (s *UploadPackSuite) TestCommandNoOutput(c *C) {
c.Skip("failing test")

if _, err := os.Stat("/bin/true"); os.IsNotExist(err) {
if _, err := os.Stat("/bin/true"); errors.Is(err, os.ErrNotExist) {
c.Skip("/bin/true not found")
}

Expand All @@ -56,7 +57,7 @@ func (s *UploadPackSuite) TestCommandNoOutput(c *C) {
}

func (s *UploadPackSuite) TestMalformedInputNoErrors(c *C) {
if _, err := os.Stat("/usr/bin/yes"); os.IsNotExist(err) {
if _, err := os.Stat("/usr/bin/yes"); errors.Is(err, os.ErrNotExist) {
c.Skip("/usr/bin/yes not found")
}

Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/ssh/auth_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func filterKnownHostsFiles(files ...string) ([]string, error) {
continue
}

if !os.IsNotExist(err) {
if !errors.Is(err, os.ErrNotExist) {
return nil, err
}
}
Expand Down
12 changes: 6 additions & 6 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error)
}

if _, err := dot.Stat(""); err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrRepositoryNotExists
}

Expand Down Expand Up @@ -347,7 +347,7 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
fs = osfs.New(path)

pathinfo, err := fs.Stat("/")
if !os.IsNotExist(err) {
if !errors.Is(err, os.ErrNotExist) {
if pathinfo == nil {
return nil, nil, err
}
Expand All @@ -361,7 +361,7 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
// no error; stop
break
}
if !os.IsNotExist(err) {
if !errors.Is(err, os.ErrNotExist) {
// unknown error; stop
return nil, nil, err
}
Expand Down Expand Up @@ -420,7 +420,7 @@ func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (bfs billy.Files

func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err error) {
f, err := fs.Open("commondir")
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
if err != nil {
Expand All @@ -439,7 +439,7 @@ func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err
commonDir = osfs.New(filepath.Join(fs.Root(), path))
}
if _, err := commonDir.Stat(""); err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrRepositoryIncomplete
}

Expand Down Expand Up @@ -504,7 +504,7 @@ func newRepository(s storage.Storer, worktree billy.Filesystem) *Repository {
func checkIfCleanupIsNeeded(path string) (cleanup bool, cleanParent bool, err error) {
fi, err := osfs.Default.Stat(path)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return true, true, nil
}

Expand Down
4 changes: 2 additions & 2 deletions repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ func (s *RepositorySuite) TestPlainCloneContextNonExistentWithExistentDir(c *C)
c.Assert(err, Equals, transport.ErrRepositoryNotFound)

_, err = fs.Stat(dir)
c.Assert(os.IsNotExist(err), Equals, false)
c.Assert(errors.Is(err, os.ErrNotExist), Equals, false)

names, err := fs.ReadDir(dir)
c.Assert(err, IsNil)
Expand All @@ -1106,7 +1106,7 @@ func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNonExistentDir(c *
c.Assert(err, Equals, transport.ErrRepositoryNotFound)

_, err = fs.Stat(repoDir)
c.Assert(os.IsNotExist(err), Equals, true)
c.Assert(errors.Is(err, os.ErrNotExist), Equals, true)
}

func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNotDir(c *C) {
Expand Down
3 changes: 2 additions & 1 deletion storage/filesystem/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package filesystem

import (
"errors"
"os"

"github.com/go-git/go-git/v5/config"
Expand All @@ -15,7 +16,7 @@ type ConfigStorage struct {
func (c *ConfigStorage) Config() (conf *config.Config, err error) {
f, err := c.dir.Config()
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return config.NewConfig(), nil
}

Expand Down
30 changes: 15 additions & 15 deletions storage/filesystem/dotgit/dotgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (d *DotGit) Initialize() error {
continue
}

if !os.IsNotExist(err) {
if !errors.Is(err, os.ErrNotExist) {
return err
}

Expand Down Expand Up @@ -200,7 +200,7 @@ func (d *DotGit) ShallowWriter() (billy.File, error) {
func (d *DotGit) Shallow() (billy.File, error) {
f, err := d.fs.Open(shallowPath)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}

Expand Down Expand Up @@ -235,7 +235,7 @@ func (d *DotGit) objectPacks() ([]plumbing.Hash, error) {
packDir := d.fs.Join(objectsPath, packPath)
files, err := d.fs.ReadDir(packDir)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}

Expand Down Expand Up @@ -284,7 +284,7 @@ func (d *DotGit) objectPackOpen(hash plumbing.Hash, extension string) (billy.Fil
path := d.objectPackPath(hash, extension)
pack, err := d.fs.Open(path)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, ErrPackfileNotFound
}

Expand Down Expand Up @@ -441,7 +441,7 @@ func (d *DotGit) ForEachObjectHash(fun func(plumbing.Hash) error) error {
func (d *DotGit) forEachObjectHash(fun func(plumbing.Hash) error) error {
files, err := d.fs.ReadDir(objectsPath)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil
}

Expand Down Expand Up @@ -612,7 +612,7 @@ func (d *DotGit) Object(h plumbing.Hash) (billy.File, error) {
}

obj1, err1 := d.fs.Open(d.objectPath(h))
if os.IsNotExist(err1) && d.hasIncomingObjects() {
if errors.Is(err1, os.ErrNotExist) && d.hasIncomingObjects() {
obj2, err2 := d.fs.Open(d.incomingObjectPath(h))
if err2 != nil {
return obj1, err1
Expand All @@ -630,7 +630,7 @@ func (d *DotGit) ObjectStat(h plumbing.Hash) (os.FileInfo, error) {
}

obj1, err1 := d.fs.Stat(d.objectPath(h))
if os.IsNotExist(err1) && d.hasIncomingObjects() {
if errors.Is(err1, os.ErrNotExist) && d.hasIncomingObjects() {
obj2, err2 := d.fs.Stat(d.incomingObjectPath(h))
if err2 != nil {
return obj1, err1
Expand All @@ -645,7 +645,7 @@ func (d *DotGit) ObjectDelete(h plumbing.Hash) error {
d.cleanObjectList()

err1 := d.fs.Remove(d.objectPath(h))
if os.IsNotExist(err1) && d.hasIncomingObjects() {
if errors.Is(err1, os.ErrNotExist) && d.hasIncomingObjects() {
err2 := d.fs.Remove(d.incomingObjectPath(h))
if err2 != nil {
return err1
Expand Down Expand Up @@ -752,7 +752,7 @@ type refsRecv func(*plumbing.Reference) bool
func (d *DotGit) findPackedRefs(recv refsRecv) error {
f, err := d.fs.Open(packedRefsPath)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err
Expand Down Expand Up @@ -789,7 +789,7 @@ func (d *DotGit) RemoveRef(name plumbing.ReferenceName) error {
// Drop down to remove it from the packed refs file, too.
}

if err != nil && !os.IsNotExist(err) {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}

Expand Down Expand Up @@ -836,7 +836,7 @@ func (d *DotGit) openAndLockPackedRefs(doCreate bool) (
for {
f, err = d.fs.OpenFile(packedRefsPath, openFlags, 0600)
if err != nil {
if os.IsNotExist(err) && !doCreate {
if errors.Is(err, os.ErrNotExist) && !doCreate {
return nil, nil
}

Expand Down Expand Up @@ -949,7 +949,7 @@ func (d *DotGit) addRefsFromRefDir(refs *[]*plumbing.Reference, seen map[plumbin
func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath []string, seen map[plumbing.ReferenceName]bool) error {
files, err := d.fs.ReadDir(d.fs.Join(relPath...))
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
// a race happened, and our directory is gone now
return nil
}
Expand All @@ -968,7 +968,7 @@ func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath []strin
}

ref, err := d.readReferenceFile(".", strings.Join(newRelPath, "/"))
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
// a race happened, and our file is gone now
continue
}
Expand All @@ -988,7 +988,7 @@ func (d *DotGit) walkReferencesTree(refs *[]*plumbing.Reference, relPath []strin
func (d *DotGit) addRefFromHEAD(refs *[]*plumbing.Reference) error {
ref, err := d.readReferenceFile(".", "HEAD")
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil
}

Expand Down Expand Up @@ -1100,7 +1100,7 @@ func (d *DotGit) PackRefs() (err error) {
for _, ref := range refs[:numLooseRefs] {
path := d.fs.Join(".", ref.Name().String())
err = d.fs.Remove(path)
if err != nil && !os.IsNotExist(err) {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
}
Expand Down
3 changes: 2 additions & 1 deletion storage/filesystem/dotgit/reader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotgit

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -26,7 +27,7 @@ func (e *EncodedObject) Hash() plumbing.Hash {
func (e *EncodedObject) Reader() (io.ReadCloser, error) {
f, err := e.dir.Object(e.h)
if err != nil {
if os.IsNotExist(err) {
if errors.Is(err, os.ErrNotExist) {
return nil, plumbing.ErrObjectNotFound
}

Expand Down
Loading

0 comments on commit 885fdc0

Please sign in to comment.