summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-07-21 04:37:00 +0200
committerGitHub <noreply@github.com>2021-07-21 03:37:00 +0100
commit09a4364b2197520c3c6bb0fbcac26eed77c3af2f (patch)
tree2386cac949fd14cd8a91088158e9d9ab0d24f64b /modules
parent0c3467ffb719eed9ed1d6a42be9491af44a1d14d (diff)
downloadgitea-09a4364b2197520c3c6bb0fbcac26eed77c3af2f.tar.gz
gitea-09a4364b2197520c3c6bb0fbcac26eed77c3af2f.zip
Add TestPrepareWikiFileName (#16487) (#16498)
* Add TestPrepareWikiFileName * use LsTree as LsFiles is index only * ajust other tests Co-authored-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r--modules/git/tree.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/git/tree.go b/modules/git/tree.go
index 059f0a8287..3671f421e9 100644
--- a/modules/git/tree.go
+++ b/modules/git/tree.go
@@ -6,6 +6,7 @@
package git
import (
+ "bytes"
"strings"
)
@@ -45,3 +46,23 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
}
return g, nil
}
+
+// LsTree checks if the given filenames are in the tree
+func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error) {
+ cmd := NewCommand("ls-tree", "-z", "--name-only", "--", ref)
+ for _, arg := range filenames {
+ if arg != "" {
+ cmd.AddArguments(arg)
+ }
+ }
+ res, err := cmd.RunInDirBytes(repo.Path)
+ if err != nil {
+ return nil, err
+ }
+ filelist := make([]string, 0, len(filenames))
+ for _, line := range bytes.Split(res, []byte{'\000'}) {
+ filelist = append(filelist, string(line))
+ }
+
+ return filelist, err
+}