Update Vendors (#250)
update go min version Update Vendors: * code.gitea.io/gitea-vet v0.2.0 -> v0.2.1 * code.gitea.io/sdk/gitea v0.13.0 -> v0.13.1 * github.com/AlecAivazis/survey v2.1.1 -> v2.2.2 * github.com/adrg/xdg v0.2.1 -> v0.2.2 * github.com/araddon/dateparse d820a6159ab1 -> 8aadafed4dc4 * github.com/go-git/go-git v5.1.0 -> v5.2.0 * github.com/muesli/termenv v0.7.2 -> v0.7.4 * github.com/stretchr/testify v1.5.1 -> v1.6.1 * github.com/urfave/cli v2.2.0 -> v2.3.0 Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/250 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: mrsdizzie <info@mrsdizzie.com> Co-Authored-By: 6543 <6543@noreply.gitea.io> Co-Committed-By: 6543 <6543@noreply.gitea.io>
This commit is contained in:
124
vendor/github.com/go-git/go-git/v5/worktree_status.go
generated
vendored
124
vendor/github.com/go-git/go-git/v5/worktree_status.go
generated
vendored
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/go-git/go-billy/v5/util"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
@@ -264,7 +265,77 @@ func diffTreeIsEquals(a, b noder.Hasher) bool {
|
||||
// the worktree to the index. If any of the files is already staged in the index
|
||||
// no error is returned. When path is a file, the blob.Hash is returned.
|
||||
func (w *Worktree) Add(path string) (plumbing.Hash, error) {
|
||||
// TODO(mcuadros): remove plumbing.Hash from signature at v5.
|
||||
// TODO(mcuadros): deprecate in favor of AddWithOption in v6.
|
||||
return w.doAdd(path, make([]gitignore.Pattern, 0))
|
||||
}
|
||||
|
||||
func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string, ignorePattern []gitignore.Pattern) (added bool, err error) {
|
||||
files, err := w.Filesystem.ReadDir(directory)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(ignorePattern) > 0 {
|
||||
m := gitignore.NewMatcher(ignorePattern)
|
||||
matchPath := strings.Split(directory, string(os.PathSeparator))
|
||||
if m.Match(matchPath, true) {
|
||||
// ignore
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
name := path.Join(directory, file.Name())
|
||||
|
||||
var a bool
|
||||
if file.IsDir() {
|
||||
if file.Name() == GitDirName {
|
||||
// ignore special git directory
|
||||
continue
|
||||
}
|
||||
a, err = w.doAddDirectory(idx, s, name, ignorePattern)
|
||||
} else {
|
||||
a, _, err = w.doAddFile(idx, s, name, ignorePattern)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !added && a {
|
||||
added = true
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// AddWithOptions file contents to the index, updates the index using the
|
||||
// current content found in the working tree, to prepare the content staged for
|
||||
// the next commit.
|
||||
//
|
||||
// It typically adds the current content of existing paths as a whole, but with
|
||||
// some options it can also be used to add content with only part of the changes
|
||||
// made to the working tree files applied, or remove paths that do not exist in
|
||||
// the working tree anymore.
|
||||
func (w *Worktree) AddWithOptions(opts *AddOptions) error {
|
||||
if err := opts.Validate(w.r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if opts.All {
|
||||
_, err := w.doAdd(".", w.Excludes)
|
||||
return err
|
||||
}
|
||||
|
||||
if opts.Glob != "" {
|
||||
return w.AddGlob(opts.Glob)
|
||||
}
|
||||
|
||||
_, err := w.Add(opts.Path)
|
||||
return err
|
||||
}
|
||||
|
||||
func (w *Worktree) doAdd(path string, ignorePattern []gitignore.Pattern) (plumbing.Hash, error) {
|
||||
s, err := w.Status()
|
||||
if err != nil {
|
||||
return plumbing.ZeroHash, err
|
||||
@@ -280,9 +351,9 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) {
|
||||
|
||||
fi, err := w.Filesystem.Lstat(path)
|
||||
if err != nil || !fi.IsDir() {
|
||||
added, h, err = w.doAddFile(idx, s, path)
|
||||
added, h, err = w.doAddFile(idx, s, path, ignorePattern)
|
||||
} else {
|
||||
added, err = w.doAddDirectory(idx, s, path)
|
||||
added, err = w.doAddDirectory(idx, s, path, ignorePattern)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -296,42 +367,11 @@ func (w *Worktree) Add(path string) (plumbing.Hash, error) {
|
||||
return h, w.r.Storer.SetIndex(idx)
|
||||
}
|
||||
|
||||
func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string) (added bool, err error) {
|
||||
files, err := w.Filesystem.ReadDir(directory)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
name := path.Join(directory, file.Name())
|
||||
|
||||
var a bool
|
||||
if file.IsDir() {
|
||||
if file.Name() == GitDirName {
|
||||
// ignore special git directory
|
||||
continue
|
||||
}
|
||||
a, err = w.doAddDirectory(idx, s, name)
|
||||
} else {
|
||||
a, _, err = w.doAddFile(idx, s, name)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !added && a {
|
||||
added = true
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// AddGlob adds all paths, matching pattern, to the index. If pattern matches a
|
||||
// directory path, all directory contents are added to the index recursively. No
|
||||
// error is returned if all matching paths are already staged in index.
|
||||
func (w *Worktree) AddGlob(pattern string) error {
|
||||
// TODO(mcuadros): deprecate in favor of AddWithOption in v6.
|
||||
files, err := util.Glob(w.Filesystem, pattern)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -360,9 +400,9 @@ func (w *Worktree) AddGlob(pattern string) error {
|
||||
|
||||
var added bool
|
||||
if fi.IsDir() {
|
||||
added, err = w.doAddDirectory(idx, s, file)
|
||||
added, err = w.doAddDirectory(idx, s, file, make([]gitignore.Pattern, 0))
|
||||
} else {
|
||||
added, _, err = w.doAddFile(idx, s, file)
|
||||
added, _, err = w.doAddFile(idx, s, file, make([]gitignore.Pattern, 0))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -383,10 +423,18 @@ func (w *Worktree) AddGlob(pattern string) error {
|
||||
|
||||
// doAddFile create a new blob from path and update the index, added is true if
|
||||
// the file added is different from the index.
|
||||
func (w *Worktree) doAddFile(idx *index.Index, s Status, path string) (added bool, h plumbing.Hash, err error) {
|
||||
func (w *Worktree) doAddFile(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern) (added bool, h plumbing.Hash, err error) {
|
||||
if s.File(path).Worktree == Unmodified {
|
||||
return false, h, nil
|
||||
}
|
||||
if len(ignorePattern) > 0 {
|
||||
m := gitignore.NewMatcher(ignorePattern)
|
||||
matchPath := strings.Split(path, string(os.PathSeparator))
|
||||
if m.Match(matchPath, true) {
|
||||
// ignore
|
||||
return false, h, nil
|
||||
}
|
||||
}
|
||||
|
||||
h, err = w.copyFileToStorage(path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user