Dateien nach „modules/git“ hochladen

This commit is contained in:
davrot 2025-01-27 20:49:15 +00:00
parent 157484d50c
commit 3c827b8be7

View file

@ -6,14 +6,14 @@ package git
import (
"bytes"
"context"
"errors"
"os"
"path/filepath"
"strings"
"errors"
"code.gitea.io/gitea/modules/git/internal" //nolint:depguard // only this file can use the internal type CmdArg, other files and packages should use AddXxx functions
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/git/internal" //nolint:depguard // only this file can use the internal type CmdArg, other files and packages should use AddXxx functions
)
// ReadTreeToIndex reads a treeish to the index
@ -105,29 +105,27 @@ func (repo *Repository) LsFiles(filenames ...string) ([]string, error) {
}
// Gives a list of all files in a directory and below
func (repo *Repository) LsFilesFromDirectory(directory string, branch string) ([]string, error) {
func (repo *Repository) LsFilesFromDirectory(directory, branch string) ([]string, error) {
if branch == "" {
return nil, errors.New("branch not found in context URL")
return nil, errors.New("branch not found in context URL")
}
cmd := NewCommand(repo.Ctx, "ls-files", internal.CmdArg("--with-tree=" + branch))
if len(directory) > 0 {
cmd = NewCommand(repo.Ctx, "ls-files", internal.CmdArg("--with-tree=" + branch), internal.CmdArg("--directory"), internal.CmdArg(directory) )
cmd := NewCommand(repo.Ctx, "ls-files", internal.CmdArg("--with-tree="+branch))
if len(directory) > 0 {
cmd = NewCommand(repo.Ctx, "ls-files", internal.CmdArg("--with-tree="+branch), internal.CmdArg("--directory"), internal.CmdArg(directory))
}
res, stderror, err := cmd.RunStdBytes(&RunOpts{Dir: repo.Path})
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
if len(stderror) > 0 {
return nil, errors.New(string(stderror))
}
if len(stderror) > 0 {
return nil, errors.New(string(stderror))
}
lines := strings.Split(string(res), "\n")
lines := strings.Split(string(res), "\n")
return lines, nil
return lines, nil
}
// RemoveFilesFromIndex removes given filenames from the index - it does not check whether they are present.