From 3c827b8be7e1e92b86a60fc670785a296a058a24 Mon Sep 17 00:00:00 2001 From: davrot Date: Mon, 27 Jan 2025 20:49:15 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20nach=20=E2=80=9Emodules/git=E2=80=9C?= =?UTF-8?q?=20hochladen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/git/repo_index.go | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/modules/git/repo_index.go b/modules/git/repo_index.go index 9fc255575d..65547b0788 100644 --- a/modules/git/repo_index.go +++ b/modules/git/repo_index.go @@ -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.