aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go55
1 files changed, 21 insertions, 34 deletions
diff --git a/repository.go b/repository.go
index 601244b..d3fbf97 100644
--- a/repository.go
+++ b/repository.go
@@ -6,7 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
- "io"
stdioutil "io/ioutil"
"os"
"path"
@@ -14,9 +13,10 @@ import (
"strings"
"time"
- "github.com/go-git/go-git/v5/storage/filesystem/dotgit"
-
"github.com/ProtonMail/go-crypto/openpgp"
+ "github.com/go-git/go-billy/v5"
+ "github.com/go-git/go-billy/v5/osfs"
+ "github.com/go-git/go-billy/v5/util"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/internal/revision"
"github.com/go-git/go-git/v5/plumbing"
@@ -26,11 +26,9 @@ import (
"github.com/go-git/go-git/v5/plumbing/storer"
"github.com/go-git/go-git/v5/storage"
"github.com/go-git/go-git/v5/storage/filesystem"
+ "github.com/go-git/go-git/v5/storage/filesystem/dotgit"
"github.com/go-git/go-git/v5/utils/ioutil"
"github.com/imdario/mergo"
-
- "github.com/go-git/go-billy/v5"
- "github.com/go-git/go-billy/v5/osfs"
)
// GitDirName this is a special folder where all the git stuff is.
@@ -275,17 +273,18 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
return nil, nil, err
}
- pathinfo, err := os.Stat(path)
- if !os.IsNotExist(err) {
- if !pathinfo.IsDir() && detect {
- path = filepath.Dir(path)
- }
- }
-
var fs billy.Filesystem
var fi os.FileInfo
for {
fs = osfs.New(path)
+
+ pathinfo, err := fs.Stat("/")
+ if !os.IsNotExist(err) {
+ if !pathinfo.IsDir() && detect {
+ fs = osfs.New(filepath.Dir(path))
+ }
+ }
+
fi, err = fs.Stat(GitDirName)
if err == nil {
// no error; stop
@@ -429,7 +428,7 @@ func newRepository(s storage.Storer, worktree billy.Filesystem) *Repository {
}
func checkIfCleanupIsNeeded(path string) (cleanup bool, cleanParent bool, err error) {
- fi, err := os.Stat(path)
+ fi, err := osfs.Default.Stat(path)
if err != nil {
if os.IsNotExist(err) {
return true, true, nil
@@ -442,44 +441,30 @@ func checkIfCleanupIsNeeded(path string) (cleanup bool, cleanParent bool, err er
return false, false, fmt.Errorf("path is not a directory: %s", path)
}
- f, err := os.Open(path)
+ files, err := osfs.Default.ReadDir(path)
if err != nil {
return false, false, err
}
- defer ioutil.CheckClose(f, &err)
-
- _, err = f.Readdirnames(1)
- if err == io.EOF {
+ if len(files) == 0 {
return true, false, nil
}
- if err != nil {
- return false, false, err
- }
-
return false, false, nil
}
func cleanUpDir(path string, all bool) error {
if all {
- return os.RemoveAll(path)
+ return util.RemoveAll(osfs.Default, path)
}
- f, err := os.Open(path)
+ files, err := osfs.Default.ReadDir(path)
if err != nil {
return err
}
- defer ioutil.CheckClose(f, &err)
-
- names, err := f.Readdirnames(-1)
- if err != nil {
- return err
- }
-
- for _, name := range names {
- if err := os.RemoveAll(filepath.Join(path, name)); err != nil {
+ for _, fi := range files {
+ if err := util.RemoveAll(osfs.Default, osfs.Default.Join(path, fi.Name())); err != nil {
return err
}
}
@@ -890,11 +875,13 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
Name: branchName,
Merge: branchRef,
}
+
if o.RemoteName == "" {
b.Remote = "origin"
} else {
b.Remote = o.RemoteName
}
+
if err := r.CreateBranch(b); err != nil {
return err
}