aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/tree.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-10-23 22:44:45 +0800
committerGitHub <noreply@github.com>2022-10-23 22:44:45 +0800
commitdcd9fc7ee894700f702f3847d7d2a41d6a009b7e (patch)
tree76b1d6fdb2a760f3da57bbe566146d1c79ab5a87 /modules/git/tree.go
parent4eeea7b30ee5d90ed4e9410ec5c7d0252ada3a3b (diff)
downloadgitea-dcd9fc7ee894700f702f3847d7d2a41d6a009b7e.tar.gz
gitea-dcd9fc7ee894700f702f3847d7d2a41d6a009b7e.zip
Refactor git command arguments and make all arguments to be safe to be used (#21535)
Follow #21464 Make all git command arguments strictly safe. Most changes are one-to-one replacing, keep all existing logic.
Diffstat (limited to 'modules/git/tree.go')
-rw-r--r--modules/git/tree.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/modules/git/tree.go b/modules/git/tree.go
index a83336f3db..f5944dd29c 100644
--- a/modules/git/tree.go
+++ b/modules/git/tree.go
@@ -49,12 +49,9 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
// LsTree checks if the given filenames are in the tree
func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error) {
- cmd := NewCommand(repo.Ctx, "ls-tree", "-z", "--name-only", "--", ref)
- for _, arg := range filenames {
- if arg != "" {
- cmd.AddArguments(arg)
- }
- }
+ cmd := NewCommand(repo.Ctx, "ls-tree", "-z", "--name-only").
+ AddDashesAndList(append([]string{ref}, filenames...)...)
+
res, _, err := cmd.RunStdBytes(&RunOpts{Dir: repo.Path})
if err != nil {
return nil, err